Search in sources :

Example 1 with Callback

use of com.facebook.react.bridge.Callback in project native-navigation by airbnb.

the class NativeFragment method onCreateView.

@Nullable
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_native, container, false);
    final int count = getArguments().getInt(ARG_COUNT);
    Toolbar toolbar = (Toolbar) view.findViewById(R.id.toolbar);
    ((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
    toolbar.setTitle("Fragment " + count);
    toolbar.setNavigationIcon(R.drawable.n2_ic_arrow_back_white);
    toolbar.setNavigationOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getActivity().onBackPressed();
        }
    });
    view.findViewById(R.id.push).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen(newInstance(count + 1));
        }
    });
    view.findViewById(R.id.present).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Promise promise = new PromiseImpl(new Callback() {

                @Override
                public void invoke(Object... args) {
                    WritableMap map = (WritableMap) args[0];
                    ReadableMap payload = map.getMap("payload");
                    if (payload != null) {
                        String text = "Result: " + payload.getString(RESULT_TEXT);
                        Toast.makeText(getContext(), text, Toast.LENGTH_LONG).show();
                    }
                }
            }, new Callback() {

                @Override
                public void invoke(Object... args) {
                    Toast.makeText(getContext(), "Promise was rejected.", Toast.LENGTH_LONG).show();
                }
            });
            getScreenCoordinator().presentScreen(newInstance(0), promise);
        }
    });
    view.findViewById(R.id.push_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pushScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.present_rn).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().presentScreen("ScreenOne");
        }
    });
    view.findViewById(R.id.pop).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            getScreenCoordinator().pop();
        }
    });
    final EditText editText = (EditText) view.findViewById(R.id.payload);
    view.findViewById(R.id.dismiss).setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            Map<String, Object> payload = new HashMap<>();
            payload.put(RESULT_TEXT, editText.getText().toString());
            getScreenCoordinator().dismiss(Activity.RESULT_OK, payload);
        }
    });
    return view;
}
Also used : EditText(android.widget.EditText) WritableMap(com.facebook.react.bridge.WritableMap) AppCompatActivity(android.support.v7.app.AppCompatActivity) View(android.view.View) PromiseImpl(com.facebook.react.bridge.PromiseImpl) Promise(com.facebook.react.bridge.Promise) Callback(com.facebook.react.bridge.Callback) ReadableMap(com.facebook.react.bridge.ReadableMap) ReadableMap(com.facebook.react.bridge.ReadableMap) HashMap(java.util.HashMap) Map(java.util.Map) WritableMap(com.facebook.react.bridge.WritableMap) Toolbar(android.support.v7.widget.Toolbar) Nullable(android.support.annotation.Nullable)

Example 2 with Callback

use of com.facebook.react.bridge.Callback in project gl-react-native by ProjectSeptemberInc.

the class RNGLContext method shaderFailedToCompile.

public void shaderFailedToCompile(Integer id, GLShaderCompilationFailed e) {
    Callback onCompile;
    synchronized (this) {
        onCompile = onCompileCallbacks.get(id);
        onCompileCallbacks.remove(id);
    }
    if (onCompile == null) {
        Log.e("RNGLContext", e.getMessage());
    } else {
        onCompile.invoke(e.compileError);
    }
}
Also used : Callback(com.facebook.react.bridge.Callback)

Example 3 with Callback

use of com.facebook.react.bridge.Callback in project gl-react-native by ProjectSeptemberInc.

the class RNGLContext method shaderSucceedToCompile.

public void shaderSucceedToCompile(Integer id, Map<String, Integer> uniformTypes) {
    Callback onCompile;
    synchronized (this) {
        onCompile = onCompileCallbacks.get(id);
        onCompileCallbacks.remove(id);
    }
    if (onCompile != null) {
        WritableMap res = Arguments.createMap();
        WritableMap uniforms = Arguments.createMap();
        for (String key : uniformTypes.keySet()) {
            uniforms.putString(key, glTypeString(uniformTypes.get(key)));
        }
        res.putMap("uniforms", uniforms);
        onCompile.invoke(null, res);
    }
}
Also used : Callback(com.facebook.react.bridge.Callback) WritableMap(com.facebook.react.bridge.WritableMap)

Aggregations

Callback (com.facebook.react.bridge.Callback)3 WritableMap (com.facebook.react.bridge.WritableMap)2 Nullable (android.support.annotation.Nullable)1 AppCompatActivity (android.support.v7.app.AppCompatActivity)1 Toolbar (android.support.v7.widget.Toolbar)1 View (android.view.View)1 EditText (android.widget.EditText)1 Promise (com.facebook.react.bridge.Promise)1 PromiseImpl (com.facebook.react.bridge.PromiseImpl)1 ReadableMap (com.facebook.react.bridge.ReadableMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1