react-native-android-open-settings icon indicating copy to clipboard operation
react-native-android-open-settings copied to clipboard

Return promises?

Open nol13 opened this issue 6 years ago • 2 comments

Sometimes is useful to be able to run some code after you return from settings. Currently have a JavaScript helper I was using based on AppState. Not sure if there is a better 'native' way to do this, but happy to make PR to wrap the exported functions or include as a helper if this is useful to anyone. Thanks for lib!

e.g.

openDroidSetting(AndroidOpenSettings.appDetailsSettings).then(() => {
    // back from settings!
    // re-check permission and do stuff..
});

function openDroidSetting(settingFunc) {
  return new Promise((resolve, reject) => {
    const listener = (state) => {
      if (state === 'active') {
        AppState.removeEventListener('change', listener);
        resolve();
      }
    };
    AppState.addEventListener('change', listener);
    try {
      settingFunc();
    }
    catch (e) {
      AppState.removeEventListener('change', listener);
      reject(e);
    }
  });
}

nol13 avatar Jan 30 '19 20:01 nol13

same issue, did you find solution?

adirzoari avatar Feb 14 '19 17:02 adirzoari

I put in a merge request #16 but I think this may be abandoned. I built an async version of this and published it under react-native-android-open-settings-async https://github.com/chris-shaw-2011/react-native-android-open-settings-async

chris-shaw-2011 avatar Aug 27 '19 16:08 chris-shaw-2011