phamha98 / hi

note
Other
2 stars 0 forks source link

@ReactMethod #50

Open phamha98 opened 1 month ago

phamha98 commented 1 month ago

import com.facebook.react.bridge.WritableMap;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Callback;
import com.facebook.react.bridge.ReactMethod;

@ReactMethod
public void test(Callback callback) {
    WritableMap map = Arguments.createMap();
    map.putString("yourKey", "yourValue");

    // Kiểm tra callback không null trước khi gọi
    if (callback != null) {
        callback.invoke(map);
    }
}

import { NativeModules } from 'react-native';

const { YourModuleName } = NativeModules;

YourModuleName.test((map) => {
    console.log(map.yourKey); // "yourValue"
});