小编Rob*_*rge的帖子

错误:找不到符号导入 androidx.annotation.Nullable;

我安装了 Jetifier 来解决 react-native-gesture-handler 的问题,但现在我收到了这个错误:

> Task :expo-constants:compileDebugJavaWithJavac FAILED
C:\ioweu\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:6: error: cannot find symbol
import androidx.annotation.Nullable;
                          ^
  symbol:   class Nullable
  location: package androidx.annotation
C:\ioweu\node_modules\expo-constants\android\src\main\java\expo\modules\constants\ConstantsService.java:51: error: cannot find symbol
  @Nullable
   ^
  symbol:   class Nullable
  location: class ConstantsService
2 errors

FAILURE: Build failed with an exception.
Run Code Online (Sandbox Code Playgroud)

我正在使用 React Native 和 Android Studio。我对这一切还是陌生的,所以感谢任何帮助。

这是我的依赖项:

dependencies {
    implementation project(':react-native-gesture-handler')
    implementation project(':react-native-image-picker')
    implementation project(':react-native-splash-screen')
    implementation project(':react-native-screens')
    implementation project(':react-native-reanimated')
    implementation fileTree(dir: "libs", include: ["*.jar"])
    implementation "com.android.support:appcompat-v7:${rootProject.ext.supportLibVersion}"
    implementation "com.facebook.react:react-native:+"  // From node_modules

    addUnimodulesDependencies()
}
Run Code Online (Sandbox Code Playgroud)

为了解决我之前的错误,我遵循了https://github.com/facebook/react-native/issues/25483#issuecomment-508446776的内容,据我所知,它改变了我的项目以使用 …

react-native

7
推荐指数
0
解决办法
4293
查看次数

TouchableOpacity onPress() 不适用于 react-native-modal

我试图让 TouchableOpacity 与 react-native-modal 一起工作。当我按下按钮时,没有任何反应。

这是我的代码,按下按钮时,没有按下动画,也没有出现警报:

<Modal
  isVisible={this.state.modalVisible}
  onBackdropPress={() => this.setState({ modalVisible: false })}
  deviceWidth={Dimensions.get('window').width}
  deviceHeight={Dimensions.get('window').height}
  backdropColor={'rgba(29, 36, 40, 0.5)'}>
  <View style={styles.modal}>
    <Text style={styles.modalTitle}>Test modal</Text>
    <View style={modalButtons}>
      <TouchableOpacity onPress={() => alert('hello!')}><Text style={styles.modalButton}>Test</Text></TouchableOpacity>
      <TouchableOpacity onPress={() => this.setState({ modalVisible: false })}><Text style={styles.modalButton}>Close</Text></TouchableOpacity>
    </View>
  </View>
</Modal>
Run Code Online (Sandbox Code Playgroud)

我从 react-native 导入 TouchableOpacity,而不是 react-native-gesture-handler(一个解决方案提到了这一点;它对我所做的只是防止按钮不可见)。

编辑:我已将范围缩小到按钮周围的视图。当我删除以下样式时,它会起作用:

  modalButtons: {
    flex: 1,
    flexDirection: 'row',
    justifyContent: 'space-between',
    marginBottom: 30,
  },
Run Code Online (Sandbox Code Playgroud)

有没有办法让这个 flex 工作?我希望按钮并排显示。

react-native

6
推荐指数
1
解决办法
3340
查看次数

标签 统计

react-native ×2