android与React Native之间传递参数

android与React Native之间传递参数

对应

Boolean -> Bool
Integer -> Number
Double -> Number
Float -> Number
String -> String
Callback -> function
ReadableMap -> Object
ReadableArray -> Array

对应js 中的数组

   @ReactMethod
    public void show(int a, int b, Callback callback) {
//        int res = add(a, b);
//        String[] array = {"one", "two", "three"};
        WritableArray writableArray = new WritableNativeArray();
        writableArray.pushString("one");
        writableArray.pushString("two");
        writableArray.pushString("three");
        callback.invoke(writableArray);
    }

对应js 中的对象

  @ReactMethod
    public void show(int a, int b, Callback callback) {
//        int res = add(a, b);
//        String[] array = {"one", "two", "three"};
//        WritableArray writableArray = new WritableNativeArray();
//        writableArray.pushString("one");
//        writableArray.pushString("two");
//        writableArray.pushString("three");
        WritableMap writableMap = new WritableNativeMap();
        writableMap.putString("1", "first");
        writableMap.putString("2", "second");
        writableMap.putString("3", "third");
        callback.invoke(writableMap);
    }

你可能感兴趣的:(android,react,native,react.js)