react-native - 如何在 React Native 的 ActionSheetIOS 中使用 iPad 的锚点选项?
问题描述
根据https://facebook.github.io/react-native/docs/actionsheetios上提供的 React Native 文档,我们必须将一个数字传递给锚选项。老实说,我没有在整个文档中读过更模糊的句子,我完全迷失了。
anchor (number) - the node to which the action sheet should be anchored (used for iPad)
我试着玩一堆数字,但结果总是一样的。ActionSheet 打开到屏幕的左上角。
据我到目前为止所理解的,以下应该有效:
ActionSheetIOS.showActionSheetWithOptions(
{
cancelButtonIndex: buttonsArray.length - 1,
options: buttonsArray,
anchor: 51, // THIS. WHAT THE HELL IS THIS NUMBER SUPPOSED TO BE?
},
(buttonIndex) => {
.
.
.
}
);
解决方案
嗯,所以在我发布上面的问题后又挖了整整 13 分钟后,我找到了答案。
React Native 提供了一个名为findNodeHandle()
. 传递要用来锚定 ActionSheet 的组件的 ref。
让我们看看它是如何使用的。
import { findNodeHandle } from 'react-native'
.
.
.
ActionSheetIOS.showActionSheetWithOptions(
{
...
anchor: findNodeHandle(this.someFancyButtonRef)
},
(buttonIndex) => {
...
}
);
.
.
.
render() {
return (
.
.
.
<TouchableOpacity
ref={(ref) => { this.someFancyButtonRef = ref; }}
>
<Text>Some Fancy Button</Text>
</TouchableOpacity>
.
.
.
)
}
推荐阅读
- spring-boot - 在 REST 微服务上使用 Zuul Proxy、Oauth2 实现身份验证和授权
- amazon-web-services - 为 AWS S3 上传创建 API?
- java - 无法在 spring-cloud-stream 2.1.0 中检索活页夹配置
- multithreading - 为什么 Linux“系统”线程阻止我的 RT 线程工作?
- amazon-web-services - AWS Kinesis Analytics 在 ROWTIME 以外的其他字段上是否有水印和滑动窗口?
- progressive-web-apps - 在 pwabuilder 生成的 appx 文件中包含 DeviceCapability
- javascript - 提交summernote文本区域时出现验证错误
- mongodb - 新承诺不允许来自 mongo 回调的所需类型
- javascript - 将本地 JSON 数据呈现到 Tabulator 表中
- http - 数据库用户被阻止时的 REST HTTP 状态码