react-native - React Native - 标题右侧图标不会显示
问题描述
嗨,我在放置右标题图标时遇到问题,请告知如何解决。我收到错误“变量 - 导航”未找到。在其他屏幕上,我放了“静态 navigationOptions = ({ navigation }) => { 并且它正在工作。
from 'react-native'
import { UIActivityIndicator } from 'react-native-indicators'
import { CardStyleInterpolators } from 'react-navigation-stack'
import { withNavigation } from 'react-navigation'
import { ActionSheet, Picker, Icon } from 'native-base'
import { connect } from 'react-redux'
import WooComFetch, { getUrl } from '../common/WooComFetch'
import FlatListViewShop from '../common/FlatListViewShop'
import SyncStorage from 'sync-storage'
import themeStyle from '../common/Theme.style'
import ShoppingCartIcon from '../common/ShoppingCartIcon'
import Spinner from 'react-native-loading-spinner-overlay'
import { createSelector } from 'reselect'
const CANCEL_INDEX = 9
const WIDTH = Dimensions.get('window').width
class Newest extends PureComponent {
**static navigationOptions = props => {**
const headerStyle = props.navigation.getParam('headerTitle')
return {
headerTitle: headerStyle,
cardStyleInterpolator: CardStyleInterpolators.forHorizontalIOS,
headerStyle: {
backgroundColor: themeStyle.primary
},
headerTitleAlign: 'center',
headerForceInset: { top: 'never', vertical: 'never' },
headerTintColor: themeStyle.headerTintColor,
gesturesEnabled: false,
headerTitleStyle: {
fontWeight: Platform.OS === 'android' ? 'bold' : 'normal'
},
gesturesDirection: 'inverted',
headerRight: () => <ShoppingCartIcon navigation={navigation} />,
headerLeft: (
<Icon
onPress={() => props.navigation.pop()}
name={!I18nManager.isRTL ? 'arrow-back' : 'arrow-forward'}
style={{
color: themeStyle.primaryContrast,
fontSize: 25,
padding: 5,
paddingLeft: 16,
paddingRight: 16,
marginRight: 16
}}
/>
)
}
}
解决方案
你在这里缺少道具。
headerRight: () => <ShoppingCartIcon navigation={navigation} />,
这应该是
headerRight: () => <ShoppingCartIcon navigation={props.navigation} />,
推荐阅读
- amazon-dynamodb - Dynamodb UnmarshalListOfMaps 返回 InvalidUnmarshalError emptyOrigError
- node.js - 为每个项目单独升级节点版本
- machine-learning - tfidf.idf_ 在代码中这是什么意思
- python - 如何调用此函数来检查是否收到消息然后发送响应?
- r - 如何将时间序列数据填充到数据框中?
- python - Python zmq 连接
- hive - 通过返回 null 和错误的结果来进行 Hive 订单
- java - 仅提示用户输入正数
- c++ - 当节点通过函数并被接受为双指针时,如何使用双指针查找节点中的值?
- windows - Windows - 使用“.txt”或“.zip”写入文件说访问被拒绝