How to use the react-native-unimodules.Permissions.SYSTEM_BRIGHTNESS function in react-native-unimodules

To help you get started, we’ve selected a few react-native-unimodules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github NervJS / taro / packages / taro-rn / src / api / device / screen.ts View on Github external
export async function setKeepScreenOn (opts = {}) {
  let res = {errMsg: 'setKeepScreenOn:ok'} as any

  const isObject = shouleBeObject(opts)
  if (!isObject.res) {
    res = {errMsg: `setKeepScreenOn${isObject.msg}`}
    console.error(res.errMsg)
    return Promise.reject(res)
  }

  const {keepScreenOn, success, fail, complete}: any = opts
  await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS)
  const {status} = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS)

  if (status === 'granted') {
    try {
      if (keepScreenOn) {
        // activateKeepAwake()
      } else {
        // deactivateKeepAwake()
      }
      return successHandler(success, complete)(res)
    } catch (e) {
      res.errMsg = `setKeepScreenOn:fail invalid ${e}`
      return errorHandler(fail, complete)(res)
    }
  }
}
github NervJS / taro / packages / taro-rn / src / api / device / screen.ts View on Github external
export async function setScreenBrightness (opts = {}) {
  let res = {errMsg: 'setScreenBrightness:ok'}

  const isObject = shouleBeObject(opts)
  if (!isObject.res) {
    res = {errMsg: `setScreenBrightness${isObject.msg}`}
    console.error(res.errMsg)
    return Promise.reject(res)
  }

  const {value, success, fail, complete}: any = opts
  await Permissions.askAsync(Permissions.SYSTEM_BRIGHTNESS)
  const {status} = await Permissions.getAsync(Permissions.SYSTEM_BRIGHTNESS)

  if (status === 'granted') {
    try {
      await (Brightness as any).setSystemBrightnessAsync(value)
      return successHandler(success, complete)(res)
    } catch (e) {
      res.errMsg = `setScreenBrightness:fail invalid ${e}`
      return errorHandler(fail, complete)(res)
    }
  }
}