我有一个我不知道从哪里开始的错误。试图更新react-native版本 - 但它没有做到这一点..
react-native-cli: 2.0.1
react-native: 0.54.2
生产构建
该应用程序正在构建并发布到Google Play商店。所以这是编译后的生产版本。认为这可能是模块的一个问题..但不太确定..
这是我在主要组件中的导入
import React, { Component } from 'react'
import { View, Modal, Text, TextInput, StyleSheet } from 'react-native'
import { KeyboardAwareScrollView } from 'react-native-keyboard-aware-scroll-view'
java.lang.RuntimeException:
at com.facebook.react.bridge.ReactContext.handleException (ReactContext.java:313)
at com.facebook.react.bridge.GuardedRunnable.run (GuardedRunnable.java:23)
at android.os.Handler.handleCallback (Handler.java:739)
at android.os.Handler.dispatchMessage (Handler.java:95)
at android.os.Looper.loop (Looper.java:158)
at android.app.ActivityThread.main (ActivityThread.java:7225)
at java.lang.reflect.Method.invoke (Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run (ZygoteInit.java:1230)
at com.android.internal.os.ZygoteInit.main (ZygoteInit.java:1120)
Caused by: android.view.WindowManager$BadTokenException:
at android.view.ViewRootImpl.setView (ViewRootImpl.java:849)
at android.view.WindowManagerGlobal.addView (WindowManagerGlobal.java:337)
at android.view.WindowManagerImpl.addView (WindowManagerImpl.java:91)
at android.app.Dialog.show (Dialog.java:350)
at com.facebook.react.views.modal.ReactModalHostView.showOrUpdate (ReactModalHostView.java:256)
at com.facebook.react.views.modal.ReactModalHostManager.onAfterUpdateTransaction (ReactModalHostManager.java:107)
at com.facebook.react.views.modal.ReactModalHostManager.onAfterUpdateTransaction (ReactModalHostManager.java:28)
at com.facebook.react.uimanager.ViewManager.updateProperties (ViewManager.java:35)
at com.facebook.react.uimanager.NativeViewHierarchyManager.createView (NativeViewHierarchyManager.java:233)
at com.facebook.react.uimanager.UIViewOperationQueue$CreateViewOperation.execute (UIViewOperationQueue.java:153)
at com.facebook.react.uimanager.UIViewOperationQueue$1.run (UIViewOperationQueue.java:816)
at com.facebook.react.uimanager.UIViewOperationQueue.flushPendingBatches (UIViewOperationQueue.java:929)
at com.facebook.react.uimanager.UIViewOperationQueue.access$2100 (UIViewOperationQueue.java:47)
at com.facebook.react.uimanager.UIViewOperationQueue$2.runGuarded (UIViewOperationQueue.java:887)
at com.facebook.react.bridge.GuardedRunnable.run (GuardedRunnable.java:21)
我使用模态3个不同的地方。
const Credits = ({ display, toggle }) => (
<View>
<TouchableOpacity
style={[styles.button, styles.info]}
onPress={() => toggle()}
>
<Icon name="question" size={30} color="#000" />
</TouchableOpacity>
{display && (
<Modal
animationType="slide"
transparent={true}
onRequestClose={() => toggle()}
>
<View style={styles.card}>
<ScrollView>
{ ... code ... }
</ScrollView>
<TouchableOpacity
style={[styles.button, styles.close]}
onPress={() => toggle()}
>
<Icon name="close" size={30} color="#000" />
</TouchableOpacity>
</View>
</Modal>
)}
</View>
)
不知道是不是因为我使用{ display && <Modal .../> }
逻辑而不是使用道具visible={display}
???
任何帮助都将受到高度赞赏!
答案 0 :(得分:0)
因为React native工作异步;从React本机获取结果并在更新任何UI之前,检查activity.isFinishing()
以及活动是否完成不要更改UI
另一种解决方案是在某些实例变量中保存onResume()和onPause()中的活动状态,然后在从React
获取结果时检查活动状态,如果恢复活动只显示结果但是如果您的活动暂停在某处保存React
的结果,并在活动的onResume()
方法中显示结果。
另外,不要忘记检查上面的生命周期,以显示从React到用户的任何错误。来自react的任何Android UI更新都应考虑Android活动生命周期。
void onResume(){
super.onResume();
activityResumed = true;
if(showResultsOnResume){
showResultsOnResume = false;
//you have saved results from react waiting to show, show it here
}
}
void onPause(){
super.onPause();
activityResumed = false;
}
// use this method to update any UI from React
void onReactResult(/*Results or Errors from React*/){
if(activityResumed){
// show the result
}else{
showResultsOnResume = true;
// save result
}
}