【发布时间】:2020-11-27 21:34:09
【问题描述】:
我需要更新 android 和 react native 类之间的事件等状态变化?
public class MessagingService extends FirebaseMessagingService {
@Override
public void onMessageReceived(RemoteMessage remoteMessage) {
Log.d(TAG, "Push Message Received ");
buildLocalNotification(remoteMessage);
}
public void buildLocalNotification(RemoteMessage message) {
...
FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplication());
notificationHelper.showNotification(bundle);
}
}
当类扩展为 FBMessingService 时,如何创建 ReactApplicationContext 构造函数?
FBMessagingHelper notificationHelper = new FBMessagingHelper(this.getApplication());
// Getting Error as a parameter is not react app context
我需要更新IN_VIDEO_PROGRESS状态
- 当视频由
React Native开始/停止时更新为Android。 - 当视频由
Android开始/停止时更新为React Native。
public class FBMessagingHelper extends ReactContextBaseJavaModule {
private ReactApplicationContext mContext;
private static boolean IN_VIDEO_PROGRESS = false;
public FBMessagingHelper(ReactApplicationContext reactContext) { // Added into Native Modules
mContext = applicationContext;
}
@ReactMethod
public void onVideoProgress(Bolean status){
// ==== on videoProgress ====
IN_VIDEO_PROGRESS = status
}
@Nonnull
@Override
public String getName() {
return "FBMessagingHelper";
}
public void showCustomNotification(Bundle bundle) {
if (!IN_VIDEO_PROGRESS && bundle.getString("category").equals("VIDEO") {
IN_VIDEO_PROGRESS = true;
// start FullScreenNotificationActivity
}
}
}
创建的原生模块:
public class FBMessagingPackage implements ReactPackage{
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
List<NativeModule> modules = new ArrayList<>();
modules.add(new FBMessagingHelper(reactContext));
modules.add((NativeModule) new MessagingService(reactContext));
// Error: cannot be cast to nativeModule
return modules;
}
...
...
}
【问题讨论】:
标签: android ios reactjs react-native bridge