react-native - 在 react-native 中获取按 headerRight 的位置
问题描述
在 react native 中单击 headerRight 中的按钮之一时,如何获得位置?我尝试按照文档进行操作,但没有显示任何内容。这是代码:
static navigationOptions = {
headerRight: (
<View style={{marginLeft: 8, marginRight: 8, flexDirection: 'row', alignItems: 'center' }}>
<TouchableOpacity style={{ marginRight: 10 }} onPress={ () =>{ }}>
<Image style={{ width: 22, height: 22 }} source={require("../Images/search.png")} />
</TouchableOpacity>
<TouchableOpacity style={{marginLeft: 10, marginRight: 10 }} onPress={ () =>{ this.displayPosition()}}>
<Image style={{ width: 22, height: 22 }} source={require("../Images/localisation.png")} />
</TouchableOpacity>
<TouchableOpacity style={{marginLeft: 10 }} onPress={ () =>{ }}>
<Image style={{ width: 22, height: 22 }} source={require("../Images/refresh.png")} />
</TouchableOpacity>
</View>
),
};
displayPosition(){
Geolocation.getCurrentPosition(
(position) => {
this.setState({
latitude: position.coords.latitude,
longitude: position.coords.longitude,
error: null,
});
},
(error) => this.setState({ error: error.message }),
{ enableHighAccuracy: true, timeout: 20000, maximumAge: 1000 },
);
Alert.alert(this.state.latitude, this.state.longitude)
}
解决方案
请澄清一下,您是想从地理位置获取(纬度,经度)位置还是只是从 headerRight 获取项目位置?
推荐阅读
- r - 如何将 SharePoint 列表加载到 R 中的小标题中?
- android - 如果用户隐藏了通知通道,关联的前台服务是否还能成功启动?
- halide - Halide: Var 声明格式
- python-3.x - 为什么 anaconda3 安装似乎以 python2 而不是 python3 结束
- typescript - 如何在 VS 代码中禁用保存时自动加入行?
- python - 解析 XML 时出错:列表索引必须是整数或切片,而不是 Str
- powershell - 当显示名称中有特殊字符时,获取通讯组中所有显示名称的 SMTP 地址
- json - 如何正确解析和输入 graphql 结果?
- puppet - 使用 puppet 迭代一定次数
- three.js - 三个 JS 中的动画透明度