我正在使用 @react-native-community/async-storage 并不断收到此警告:
Warning: Async Storage has been extracted from react-native core and will be removed in a future release. It can now be installed and imported from '@react-native-community/async-storage' instead of 'react-native'. See https://github.com/react-native-community/react-native-async-storage
这是我的 package.json:
{
"name": "mobile_app",
"version": "0.0.1",
"private": true,
"scripts": {
"start": "node node_modules/react-native/local-cli/cli.js start",
"test": "jest"
},
"dependencies": {
"@aws-amplify/pushnotification": "^1.0.32",
"@react-native-community/async-storage": "^1.6.1",
"aws-amplify": "^1.1.32",
"aws-amplify-react-native": "^2.1.15",
"buffer": "^5.3.0",
"moment": "^2.24.0",
"react": "16.8.3",
"react-native": "0.59.9",
"react-native-ble-plx": "^1.0.3",
"react-native-calendars": "^1.208.0",
"react-native-check-box": "^2.1.7",
"react-native-dialog": "^5.6.0",
"react-native-gesture-handler": "^1.3.0", …Run Code Online (Sandbox Code Playgroud) 使用 react-navigation 你可以传递这样的参数:
this.props.navigation.navigate(screen, {param: value});
Run Code Online (Sandbox Code Playgroud)
在以前的版本中,您可以像这样访问参数:
props.navigation.state.params
Run Code Online (Sandbox Code Playgroud)
在新版本的 react-navigation (5.0) 中,它们使用功能组件,并且您似乎无法像以前那样访问参数。相反,您可以像这样编写组件和访问参数:
function HomeScreen({ navigation, route }) {
React.useEffect(() => {
if (route.params?.post) {
// Post updated, do something with `route.params.post`
// For example, send the post to the server
}
}, [route.params?.post]);
return (
<View style={{ flex: 1, alignItems: 'center', justifyContent: 'center' }}>
<Button
title="Create post"
onPress={() => navigation.navigate('CreatePost')}
/>
<Text style={{ margin: 10 }}>Post: {route.params?.post}</Text>
</View>
);
}
Run Code Online (Sandbox Code Playgroud)
如何访问传递给组件的参数,而不必将项目中的所有组件从基于类的组件更改为基于功能的组件?
我正在使用react-native、amplify 和pinpoint。
我遵循了几个指南和堆栈溢出问题来设置推送通知的 android 默认颜色和图标,如下所示:
<meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/ic_notification" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/patch_coral" />
Run Code Online (Sandbox Code Playgroud)
我有一个文件 color.xml ,其中android/app/src/main/res/values/包含以下内容:
<resources>
<color name="patch_coral">#E97A6E</color>
</resources>
Run Code Online (Sandbox Code Playgroud)
对于图标,我有可绘制的文件夹,其中android/app/src/main/res/包含ic_notification.png在 android asset studio 中生成的白色图标,如多个地方所示。
我还测试了调试和发布版本,看看这是否会改变什么;但是,推送通知仍然没有默认图标或颜色,但右侧有应用程序图标。这是一个例子:
需要更改或添加什么来获取颜色和图标来替换默认的 android 颜色和方形图标?