javascript - 为 React Native 创建 NPM 包时如何解决 iOS 中出现的问题?
问题描述
我从这里开始关注这篇文章来创建反应原生库。我已经发布了这个库并在我的本地项目中使用了它。它在 android 中运行良好,但是当我尝试在 iOS 上运行它时,它会引发如下错误:
TypeError:null 不是对象(评估 '_exampleBridge.default.showMessage')。
我已经在 xcode13 中打开了库项目,它构建成功。
提前致谢。
import React from 'react';
import { SafeAreaView, ScrollView, StatusBar, StyleSheet, Text, useColorScheme, View, Button } from 'react-native';
import {Colors,Header} from 'react-native/Libraries/NewAppScreen';
import RNExampleBridge from 'example-bridge-1.0.8'
const App = () => {
const isDarkMode = useColorScheme() === 'dark';
const backgroundStyle = {
backgroundColor: isDarkMode ? Colors.darker : Colors.lighter,
};
function showToastAlert(){
RNExampleBridge.showMessage()
}
return (
<SafeAreaView style={backgroundStyle}>
<StatusBar barStyle={isDarkMode ? 'light-content' : 'dark-content'} />
<ScrollView
contentInsetAdjustmentBehavior="automatic"
style={backgroundStyle}>
<Header />
<View
style={{
backgroundColor: isDarkMode ? Colors.black : Colors.white,
}}>
<View>
<Button title="Show Native Message" onPress={() => { showToastAlert() }}/>
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default App;
解决方案
推荐阅读
- html - 当列表也有href时,如何使文本更大?
- xslt - 根据属性值过滤 XML
- java - 为什么可以在类级别定义 Property 实例但不能将属性加载到其中?
- reactjs - 如何使用 Filestack 上传多个文件?
- python - Matplotlib 补丁 contains_point() 返回不一致的结果
- vba - 如何在vba中移动具有相同名称的幻灯片上的内容占位符
- javascript - javascript -- Uncaught ReferenceError: updateProductPrice is not defined -- 函数存在,但得到错误
- c# - WebRequest 类并将 keepAlive 设置为 false
- arrays - 在遍历数组时打破Angular中的循环的替代方法?
- visual-studio-code - FailedRequest:Visual Studio Code 上 TFS 的服务不可用 (503)