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);
    }
相关推荐
limuyang22 小时前
PDF Viewer KMP(基于 chrome 的 PDFium 内核)
android·kotlin
心平气和量大福大5 小时前
android-控件-搜索框SearchView
android·gitee
2601_962177135 小时前
【MySQL篇】聚合查询,联合查询
android·java·mysql
壮哥_icon6 小时前
【Android】批量 VectorDrawable 动态分别修改 fillColor 和 strokeColor 的踩坑与终极解决方案
android
齐天qaq7 小时前
Android 系统 APK 分区与权限
android
心平气和量大福大7 小时前
android-控件-多选框CheckBox
android·gitee
pengyu9 小时前
【Kotlin 协程修仙录 · 大乘境 · 初阶】 | 跳出三界:协程在 KMP 与后端开发中的跨平台之道
android·kotlin
XiaoLeisj9 小时前
Android Memory Profiler:堆内存指标、内存抖动与泄漏定位
android·性能优化·内存抖动·内存泄露·memory profiler
未来猫咪花9 小时前
Everything is ViewModel:让状态管理回到对象世界
android·flutter·ios