react-native - 在 React Native Library 中,我如何获取 ios 当前的 UIViewController
问题描述
android中的react native库可以使用“getCurrentActivity()”来替换“this”
final Activity activity = getCurrentActivity();
而在ios中如何使用替换“self”来获取当前的UIViewController
解决方案
对于“当前 UIViewController”,您很可能需要文件RCTPresentedViewController
中的函数RCTUtils.h
:
#import <React/RCTUtils.h>
// ...
UIViewController* vc = RCTPresentedViewController();
// ...
注意:非常旧的RN版本没有这个API,但是可以很容易地手动实现,实现很容易:RCTUtils.m
推荐阅读
- reactjs - 如何使用 setState 更新状态的一部分
- mysql - 我正在尝试使用查询将 mysql db 的数据存储到 csv 文件中,但它返回错误消息。
- mapbox-gl-js - mapbox-gl-js 围绕 lat/lng 创建一个圆圈?
- database - Neo4j:以特定的关系顺序查询两个节点之间的路径,并且只知道最后一个节点的标签
- office365api - 无法从刷新令牌中获取访问令牌
- animation - 构建后,对象不再是另一个对象的子对象
- docker - Elasticsearch Docker Compose 没有启动 - 如何?
- django - 与 pgAdmin 的远程 PostgreSQL 连接
- javascript - jQuery mouseenter 未找到 addClass 并将其应用于正确的数据属性 div
- java - 列表未在 android studio 中显示