Skip to content

Return promises?Β #8

@nol13

Description

@nol13

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);
    }
  });
}

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