Skip to content

[enhance] - no need to use AsyncStorageΒ #10

@windduong

Description

@windduong

we can use NativeModules.SettingsManager.settings.RCTDevMenu.isDebuggingRemotely instead of AsyncStorage

import { useCallback, useEffect } from 'react';

import { NativeModules, DevSettings, Platform } from 'react-native';

export const useRemoteDebugger = () => {
  const connectToRemoteDebugger = (value: boolean) => () => {
    NativeModules.DevSettings.setIsDebuggingRemotely(value);
  };

  const handleAddMenuItem = useCallback(() => {
    // Check if remote debugging is enabled
    const isDebuggingRemotely =
      !!NativeModules?.SettingsManager?.settings?.RCTDevMenu
        ?.isDebuggingRemotely;

    setTimeout(() => {
      if (Platform.OS === 'ios') {
        DevSettings.addMenuItem(
          isDebuggingRemotely ? '(*) Stop Debugging' : '(*) Debug JS Remotely',
          connectToRemoteDebugger(!isDebuggingRemotely)
        );
      } else {
        DevSettings.addMenuItem(
          '(*) Debug JS Remotely',
          connectToRemoteDebugger(true)
        );
        DevSettings.addMenuItem(
          '(*) Stop Debugging',
          connectToRemoteDebugger(false)
        );
      }
    }, 100);
  }, []);

  useEffect(() => {
    if (__DEV__) {
      handleAddMenuItem();
    }
  }, [handleAddMenuItem]);
};

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions