Cloud Defense Logo

Products

Solutions

Company

Book A Live Demo

Top 10 Examples of "react-native-unimodules in functional component" in JavaScript

Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'react-native-unimodules' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.

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)
    }
  }
}
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)
    }
  }
}
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
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)
    }
  }
}
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)
    }
  }
}
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)
    }
  }
}
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)
    }
  }
}
export async function askAsyncPermissions (PermissionsType) {
  const {status} = await Permissions.askAsync(PermissionsType)
  return status
}
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
}
const askForContactPermissionsIOS = async () => {
  const {Permissions} = require('react-native-unimodules')
  const {status} = await Permissions.askAsync(Permissions.CONTACTS)
  return expoPermissionStatusMap()[status]
}

Is your System Free of Underlying Vulnerabilities?
Find Out Now