Open Dev Menu or reload app without shaking?

后端 未结 7 713
终归单人心
终归单人心 2021-02-07 10:25

Is there a way to open dev menu or reload app without shaking the app?

Android Wireless over wifi so no usb cable Windows 10

Hot reload or Live reload is not goo

相关标签:
7条回答
  • 2021-02-07 10:40

    As @bennygenel hints, from that page you can see there is a command on Android through adb

    adb shell input keyevent 82
    

    to open menu on wireless devices

    0 讨论(0)
  • 2021-02-07 10:42

    For iOS I like to wrap my app in a component like this which allows a 3 finger touch to trigger the dev menu:

    import { NativeModules } from 'react-native';
    
    // wraps the app in a function to allow three finger dev menu access
    const DevMenuTrigger = ({ children }) => {
      const { DevMenu } = NativeModules;
      const panResponder = PanResponder.create({
        onStartShouldSetPanResponder: (evt, gestureState) => {
          if (gestureState.numberActiveTouches === 3) {
            DevMenu.show();
          }
        },
      });
      return <View style={{ flex: 1 }} {...panResponder.panHandlers}>{children}</View>;
    };
    
    const DevApp = () => (<DevMenuTrigger><App /></DevMenuTrigger>);
    
    // export default App;
    export default DevApp;
    
    0 讨论(0)
  • 2021-02-07 10:45

    I have added Shake gesture to Assistive Touch menu, and this works okay for me.

    0 讨论(0)
  • 2021-02-07 10:45

    For me only using adb shell input keyevent 82 worked

    for convenience you can add it to your scripts inside the package.json file

    something link this: "android-menu": "adb shell input keyevent 82"

    also apparently there is an issue with KK devices - solved here

    0 讨论(0)
  • 2021-02-07 10:46

    for android : in your package.json add following lines in scripts

     "reload":"adb shell input keyevent 82 && adb shell input keyevent 66 && adb shell input keyevent 66",
     "devmenu":"adb shell input keyevent 82",
     "debug":"adb shell input keyevent 82 && adb shell input keyevent 61 && adb shell input keyevent 66 && adb shell input keyevent 66"
    

    now you can run npm run devmenu to open shake menu in android, and reload to reload the app, and debug to connect to remote debugger.

    for ios : you can make a button for it somewhere in app, and let this thing only be shown when app is in dev mode.

    import {NativeModules,Platform} from "react-native"
    
    
    renderDevMenuTouchable = () => {
        if(__DEV__ && Platform.OS == "ios" ){
            return (
                <TouchableOpacity
                style={styles.touchableDebug}
                onPress={()=>{
                    NativeModules.DevMenu.reload();
                }}
                onLongPress={()=>{
                    NativeModules.DevMenu.show();
                }}
                > 
                <View style={{backgroundColor:"red",width:23,height:25}}/>
                </TouchableOpacity>
            )
        }
        else {
            return null;
        }
    
    }
    
    0 讨论(0)
  • 2021-02-07 11:01

    You can send a reload call to the device with: adb shell input keyboard text "rr"

    0 讨论(0)
提交回复
热议问题