react-native#NativeModules TypeScript Examples

The following examples show how to use react-native#NativeModules. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: utility.ts    From save-food with MIT License 7 votes vote down vote up
getLocale = () => {
	if (Platform.OS === 'web') {
		return { lang: 'en', currency: 'USD' }
	}

	const locale =
		Platform.OS === 'ios'
			? NativeModules.SettingsManager.settings.AppleLocale
			: NativeModules.I18nManager.localeIdentifier
	if (locale === 'pl_PL') {
		return { lang: 'pl', currency: 'PLN' }
	}
	return { lang: 'en', currency: 'USD' }
}
Example #2
Source File: resolveAssetSource.web.ts    From nlw2-proffy with MIT License 6 votes vote down vote up
function getSourceCodeScriptURL(): string | undefined | null {
  if (_sourceCodeScriptURL) {
    return _sourceCodeScriptURL;
  }

  let sourceCode = nativeExtensions && nativeExtensions.SourceCode;
  if (!sourceCode) {
    sourceCode = NativeModules && NativeModules.SourceCode;
  }
  _sourceCodeScriptURL = sourceCode.scriptURL;
  return _sourceCodeScriptURL;
}
Example #3
Source File: MPCScreen.tsx    From safetraceapi with GNU General Public License v3.0 6 votes vote down vote up
componentDidMount() {
    NativeModules.MPCModule.splitShares(this.splitInput)
      .then((data: string) => {
        this.setState({
          splitOutput: data,
        });
      })
      .catch((err: any) => alert("err: " + err));

    NativeModules.MPCModule.joinShares(this.joinInput)
      .then((data: any) => {
        this.setState({
          joinOutput: data,
        });
      })
      .catch((err: any) => alert("err: " + err));
  }
Example #4
Source File: Splash.action.tsx    From react-native-chatapp-socket with MIT License 6 votes vote down vote up
languageDetactor = async () => {
    try{
        // Determine phone language
        let language = null;
        if (Platform.OS == 'ios')
            language = NativeModules.SettingsManager.settings.AppleLocale;
        else
            language = NativeModules.I18nManager.localeIdentifier;
        // Read language data
        let customData;
        if (language === 'tr_TR')
            customData = require(`../../assets/languages/tr.json`);
        else customData = require(`../../assets/languages/en.json`); 
        store.dispatch({ type: LANGUAGE, payload: customData });
        return;
    }catch(err){ return }
}
Example #5
Source File: i18n.ts    From ito-app with GNU General Public License v3.0 6 votes vote down vote up
function getSystemLocale(): string {
  let locale;
  // iOS
  if (
    NativeModules.SettingsManager &&
    NativeModules.SettingsManager.settings &&
    NativeModules.SettingsManager.settings.AppleLanguages
  ) {
    locale = NativeModules.SettingsManager.settings.AppleLanguages[0];
    // Android
  } else if (NativeModules.I18nManager) {
    locale = NativeModules.I18nManager.localeIdentifier;
  }

  if (typeof locale === 'undefined') {
    console.log('Couldnt get locale');
    return 'en';
  }

  return locale;
}
Example #6
Source File: contact-tracing-provider.tsx    From SQUID with MIT License 6 votes vote down vote up
/**
   * Read Contact Tracer service latest state
   *
   * Read state, set isServiceEnabled and call enable() to init
   */
  refreshTracerService() {
    NativeModules.ContactTracerModule.isTracerServiceEnabled()
      .then((enabled) => {
        this.setState({
          isServiceEnabled: enabled,
        })
        // Refresh Tracer Service Status in case the service is down
        if (enabled) return this.enable()
        else return ''
      })
      .then(() => {})
  }
Example #7
Source File: index.ts    From react-native-file-access with MIT License 6 votes vote down vote up
Dirs: {
  /**
   * Temporary files. System/user may delete these if device storage is low.
   */
  CacheDir: string;

  /**
   * System recommended location for SQLite files.
   *
   * Android only.
   */
  DatabaseDir?: string;

  /**
   * Persistent data. Generally user created content.
   */
  DocumentDir: string;

  /**
   * Persistent app internal data.
   *
   * iOS & MacOS only.
   */
  LibraryDir?: string;

  /**
   * App's default root directory.
   */
  MainBundleDir: string;

  /**
   * Root path to removable media. Prefer `cpExternal()` when possible, as
   * Android discourages this access method.
   *
   * Android only.
   */
  SDCardDir?: string;
} = NativeModules.RNFileAccess?.getConstants()
Example #8
Source File: lnd.ts    From react-native-lightning with MIT License 6 votes vote down vote up
constructor() {
		this.lnd = NativeModules.ReactNativeLightning;
		this.grpc = new GrpcAction(this.lnd);
		this.stateService = new StateService(this.grpc);
		this.walletUnlocker = new WalletUnlocker(this.grpc);
		this.logListeners = [];

		this.grpc.lndEvent.addListener(EStreamEventTypes.Logs, this.processLogListeners.bind(this));
	}
Example #9
Source File: LocaleActions.ts    From hamagen-react-native with MIT License 6 votes vote down vote up
getActiveLocale = async () => {
  let locale = IS_IOS ? NativeModules.SettingsManager.settings.AppleLocale : NativeModules.I18nManager.localeIdentifier;

  if (locale === undefined) {
    // eslint-disable-next-line prefer-destructuring
    locale = NativeModules.SettingsManager.settings.AppleLanguages[0];
  }

  const activeLocale: string = (await AsyncStorage.getItem(CURRENT_LOCALE) || locale)?.substr?.(0, 2);

  if (activeLocale === 'iw') {
    return 'he';
  }

  return activeLocale;
}
Example #10
Source File: PositiveResult.tsx    From ito-app with GNU General Public License v3.0 5 votes vote down vote up
{ItoBluetooth} = NativeModules
Example #11
Source File: FBGraphRequestManager.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
NativeGraphRequestManager = NativeModules.FBGraphRequest
Example #12
Source File: index.tsx    From react-native-network-client with Apache License 2.0 5 votes vote down vote up
{ APIClient: NativeAPIClient } = NativeModules
Example #13
Source File: FBLoginManager.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
LoginManager = NativeModules.FBLoginManager
Example #14
Source File: GiphyUi.ts    From react-native-giphy-ui with MIT License 5 votes vote down vote up
{ RNGiphyUI } = NativeModules
Example #15
Source File: FBSettings.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
Settings = NativeModules.FBSettings
Example #16
Source File: OnboardingHow.tsx    From ito-app with GNU General Public License v3.0 5 votes vote down vote up
OnboardingHow: React.FC<{
  navigation: OnboardingHowScreenNavigationProp;
}> = ({navigation}) => {
  const {t} = useTranslation();

  return (
    <View style={global.container}>
      <Header />
      <View style={styles.explanationRow}>
        <Icon name="bluetooth" size={40} color="white" style={styles.icon} />
        <Text style={styles.explanation}>{t('onboardingHow.bluetooth')}</Text>
      </View>
      <View style={styles.explanationRow}>
        <Text style={styles.explanation}>{t('onboardingHow.smartphone')}</Text>
        <Icon name="smartphone" size={40} color="white" style={styles.icon} />
      </View>
      <View style={styles.explanationRow}>
        <Icon name="bell" size={40} color="white" style={styles.icon} />
        <Text style={styles.explanation}>{t('onboardingHow.bell')}</Text>
      </View>
      <View style={styles.explanationRow}>
        <Text style={styles.explanation}>{t('onboardingHow.shield2')}</Text>
        <ShieldIcon2
          style={styles.icon}
          height={68}
          width={68}
          viewBox="0 -32 120 180"
        />
      </View>
      <BasicButton
        title={t('onboardingHow.buttonTitleGetStarted')}
        onPress={async (): Promise<void> => {
          const granted = await PermissionsAndroid.request(
            PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
            {
              title: 'We need your consent',
              message:
                'ito needs to have access to your location to find other ito devices.\n\n' +
                'This will allow others around you to see that you are running ito.',
              buttonPositive: 'Continue',
            },
          );
          if (granted === PermissionsAndroid.RESULTS.GRANTED) {
            NativeModules.ItoBluetooth.restartTracing();
          }
          navigation.navigate('HomeTour');
        }}
      />
    </View>
  );
}
Example #17
Source File: FBShareDialog.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
ShareDialog = NativeModules.FBShareDialog
Example #18
Source File: NativeAppearance.tsx    From nlw2-proffy with MIT License 5 votes vote down vote up
NativeAppearance = NativeModules.RNCAppearance
Example #19
Source File: module.ts    From react-native-keyboard-area with MIT License 5 votes vote down vote up
{ RNKeyboard: KBModule } = NativeModules
Example #20
Source File: index.tsx    From react-native-detector with MIT License 5 votes vote down vote up
{ Detector } = NativeModules
Example #21
Source File: index.tsx    From react-native-network-client with Apache License 2.0 5 votes vote down vote up
{ GenericClient: NativeGenericClient } = NativeModules
Example #22
Source File: FBAppLink.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
AppLink = NativeModules.FBAppLink
Example #23
Source File: index.tsx    From react-native-network-client with Apache License 2.0 5 votes vote down vote up
{ WebSocketClient: NativeWebSocketClient } = NativeModules
Example #24
Source File: index.tsx    From react-native-kakao-share-link with MIT License 5 votes vote down vote up
{ KakaoShareLink } = NativeModules
Example #25
Source File: RootErrorBoundary.tsx    From react-native-template with MIT License 5 votes vote down vote up
/**
   * TODO: Restart app instead of reload.
   */
  reloadApp = () => {
    NativeModules.DevSettings.reload()
  }
Example #26
Source File: phone.ts    From lets-fork-native with MIT License 5 votes vote down vote up
getLocale = (): string => (Platform.OS === 'ios'
  ? NativeModules.SettingsManager.settings.AppleLocale
    || NativeModules.SettingsManager.settings.AppleLanguages[0] // iOS 13
  : NativeModules.I18nManager.localeIdentifier)
Example #27
Source File: FBAuthenticationToken.ts    From react-native-fbsdk-next with MIT License 5 votes vote down vote up
AuthenticationToken = NativeModules.FBAuthenticationToken
Example #28
Source File: nativeModule.ts    From react-native-msal with MIT License 5 votes vote down vote up
RNMSAL: RNMSALNativeModule = NativeModules.RNMSAL
Example #29
Source File: NativeStripeSdk.tsx    From stripe-react-native with MIT License 5 votes vote down vote up
{ StripeSdk } = NativeModules