How to use react-native-unimodules - 10 common examples

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 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 / media / audio.ts View on Github external
async play () {
    const status = await askAsyncPermissions(Permissions.AUDIO_RECORDING)

    if (status !== 'granted') {
      const res = {errMsg: `Permissions denied!`}
      return Promise.reject(res)
    }

    const soundStatus = await this.soundObject.getStatusAsync()
    try {
      if (soundStatus.isLoaded === false && (soundStatus as any).isPlaying === undefined) {
        // First load
        await this._firstPlay()

      } else {
        await this.soundObject.playAsync()
      }
      // TODO
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)
    }
  }
}
github NervJS / taro / packages / taro-rn / src / api / device / screen.ts View on Github external
export async function getScreenBrightness (opts = {}) {
  let res = {errMsg: 'getScreenBrightness:ok'} as any

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

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

  if (status === 'granted') {
    try {
      res.num = await (Brightness as any).getBrightnessAsync()
      return successHandler(success, complete)(res)
    } catch (e) {
      res.errMsg = `getScreenBrightness: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 getScreenBrightness (opts = {}) {
  let res = {errMsg: 'getScreenBrightness:ok'} as any

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

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

  if (status === 'granted') {
    try {
      res.num = await (Brightness as any).getBrightnessAsync()
      return successHandler(success, complete)(res)
    } catch (e) {
      res.errMsg = `getScreenBrightness: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)
    }
  }
}
github NervJS / taro / packages / taro-rn / src / api / utils / index.js View on Github external
export async function askAsyncPermissions (PermissionsType) {
  const {status} = await Permissions.askAsync(PermissionsType)
  return status
}
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
export const requestAudioPermission = async () => {
  let chargeForward = true
  const {Permissions} = require('react-native-unimodules')
  let {status} = await Permissions.getAsync(Permissions.AUDIO_RECORDING)
  if (status === Permissions.PermissionStatus.UNDETERMINED) {
    if (isIOS) {
      const askRes = await Permissions.askAsync(Permissions.AUDIO_RECORDING)
      status = askRes.status
    } else {
      const askRes = await PermissionsAndroid.request(PermissionsAndroid.PERMISSIONS.RECORD_AUDIO)
      switch (askRes) {
        case 'never_ask_again':
        case 'denied':
          status = Permissions.PermissionStatus.DENIED
      }
    }
    chargeForward = false
  }
  if (status === Permissions.PermissionStatus.DENIED) {
    throw new Error('Please allow Keybase to access the microphone in the phone settings.')
  }
  return chargeForward
}
github keybase / client / shared / actions / platform-specific / index.native.tsx View on Github external
const askForContactPermissionsIOS = async () => {
  const {Permissions} = require('react-native-unimodules')
  const {status} = await Permissions.askAsync(Permissions.CONTACTS)
  return expoPermissionStatusMap()[status]
}