1.0.8 • Published 6 years ago

react-native-locale-listener v1.0.8

Weekly downloads
39
License
-
Repository
-
Last release
6 years ago

react-native-locale-listener

The library allows you to listen to locale changes on your device. for example reloading the app when the locale changed.

Getting started

$ npm install react-native-locale-listener --save

Mostly automatic installation

$ react-native link react-native-locale-listener

Manual installation

Android

  1. Open up android/app/src/main/java/[...]/MainApplication.java
  • Add import com.toyberman.localeReload.RNReactNativeLocalePackage; to the imports at the top of the file
  • Add new RNReactNativeLocalePackage() to the list returned by the getPackages() method
  1. Append the following lines to android/settings.gradle:
    include ':react-native-locale-listener'
    project(':react-native-locale-listener').projectDir = new File(rootProject.projectDir, 	'../node_modules/react-native-locale-listener/android')
  2. Insert the following lines inside the dependencies block in android/app/build.gradle:
      compile project(':react-native-locale-listener')

Usage

add to AndroidManifest.xml this :

android:configChanges="layoutDirection|locale"

and to MainActivity.java

import android.content.res.Configuration;
import android.content.Intent;
...
@Override
public void onConfigurationChanged(Configuration newConfig) {
    super.onConfigurationChanged(newConfig);
    Intent intent = new Intent("onConfigurationChanged");
    intent.putExtra("newConfig", newConfig);
    this.sendBroadcast(intent);
}

you can use it anywhere

import RNReactNativeLocale from 'react-native-locale-listener';

changeLayout(language) {
    // Do what you need here
    RNRestart.Restart();
}

componentDidMount () {
  RNReactNativeLocale.addLocaleListener(this.changeLayout)
}

componentWillUnmount() {
  // prevent leaking
  RNReactNativeLocale.removeLocaleListener(this.changeLayout)
}
1.0.8

6 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.24

7 years ago

1.0.23

7 years ago

1.0.22

7 years ago

1.0.21

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago