【问题标题】:How to load the dev menu or reload react-native app in physical device programmaticaly如何以编程方式在物理设备中加载开发菜单或重新加载 react-native 应用程序
【发布时间】:2016-10-21 14:33:13
【问题描述】:

我想加载开发菜单或触发重新加载,而不必每次都摇晃我的手机……因为这有点烦人。

我知道这是可能的,因为实时重新加载使用它。这是我在source: RCTDevMenu.h 中找到的 /** * Manually reload the application. Equivalent to calling [bridge reload] * directly, but can be called from JS. */ - (void)reload; 知道如何实现这一点(从 JS 调用重新加载)吗?

还有一些类似的questions

【问题讨论】:

  • 你只需要长按菜单键

标签: react-native


【解决方案1】:

虽然这是从 obj-c 而不是 js 调用的,但以下解决了我在 RN 0.43.0 的 iOS 上使用 Cocoapods 的问题,并有望帮助其他将 RN 嵌入现有 iOS 应用程序的人:

首先确保您的 Podfile 中有“DevSupport”子规范:

pod 'React', :path => './js/node_modules/react-native', :subspecs => [
  'Core',
  'DevSupport'
]

然后导入 React/RCTDevMenu.h,它在 RCTBridge 上提供了一个类别,可让您访问 RCTDevMenu。

#import <React/RCTBridge.h>
#import <React/RCTDevMenu.h>

...

RCTBridge *bridge = [[RCTBridge alloc] initWithBundleURL:jsCodeLocation
                                          moduleProvider:nil
                                           launchOptions:nil];
[bridge.devMenu show];

【讨论】:

    【解决方案2】:
    1. import { NativeModules } from 'react-native';

    2. 在您要执行重新加载的 JS 代码中: NativeModules.DevMenu.reload();

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-12-14
      • 1970-01-01
      • 1970-01-01
      • 2018-09-06
      • 2020-07-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多