How to use cozy-device-helper - 10 common examples

To help you get started, we’ve selected a few cozy-device-helper 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 cozy / cozy-ui / react / AppLinker / index.jsx View on Github external
let onClick = null
    const usingNativeApp = isMobileApp()
    const appInfo = NATIVE_APP_INFOS[slug]
    if (usingNativeApp) {
      if (nativeAppIsAvailable) {
        // If we are on the native app and the other native app is available,
        // we open the native app
        onClick = AppLinker.openNativeFromNative.bind(this, props)
        href = '#'
      } else {
        // If we are on a native app, but the other native app is not available
        // we open the web link, this is done by the href prop. We still
        // have to call the prop callback
        onClick = AppLinker.openWeb.bind(this, props)
      }
    } else if (isMobile() && appInfo) {
      // If we are on the "mobile web version", we try to open the native app
      // if it exists with an universal links. If it fails, we redirect to the web
      // version of the requested app
      // Only on iOS ATM
      if (isAndroid()) {
        onClick = AppLinker.openNativeFromWeb.bind(this, props)
      } else {
        //Since generateUniversalLink can rise an error, let's catch it to not crash
        //all the page.
        try {
          href = generateUniversalLink({ slug, nativePath, fallbackUrl: href })
        } catch (err) {
          console.error(err)
          href = '#'
        }
      }
github cozy / cozy.github.io / en / cozy-banks / src / ducks / mobile / push.js View on Github external
const handleNotification = notification => {
  if (notification.additionalData.foreground && isIOS()) {
    // on iOS the the notification does not appear if the application is in foreground
    Alerter.info(notification.title + ' : ' + notification.message)
  }
  if (flag('debug')) {
    // eslint-disable-next-line no-console
    console.log('Received notification', notification)
  }
  if (
    !notification.additionalData.foreground &&
    notification.additionalData.route
  ) {
    hashHistory.push(notification.additionalData.route)
  }
}
github cozy / cozy-ui / react / AppLinker / index.jsx View on Github external
// If we are on the native app and the other native app is available,
        // we open the native app
        onClick = AppLinker.openNativeFromNative.bind(this, props)
        href = '#'
      } else {
        // If we are on a native app, but the other native app is not available
        // we open the web link, this is done by the href prop. We still
        // have to call the prop callback
        onClick = AppLinker.openWeb.bind(this, props)
      }
    } else if (isMobile() && appInfo) {
      // If we are on the "mobile web version", we try to open the native app
      // if it exists with an universal links. If it fails, we redirect to the web
      // version of the requested app
      // Only on iOS ATM
      if (isAndroid()) {
        onClick = AppLinker.openNativeFromWeb.bind(this, props)
      } else {
        //Since generateUniversalLink can rise an error, let's catch it to not crash
        //all the page.
        try {
          href = generateUniversalLink({ slug, nativePath, fallbackUrl: href })
        } catch (err) {
          console.error(err)
          href = '#'
        }
      }
    }

    return {
      href,
      onClick
github cozy / cozy-ui / react / Popup / index.jsx View on Github external
addListeners() {
    // Listen here for message FROM popup
    window.addEventListener('message', this.handleMessage)

    if (isMobileApp()) {
      this.popup.addEventListener('loadstart', this.handleLoadStart)
      this.popup.addEventListener('exit', this.handleClose)
    }
  }
github cozy / cozy-ui / react / Viewer / Viewer.jsx View on Github external
const hasNext = currentIndex < fileCount - 1
    // this `expanded` property makes the next/previous controls cover the displayed image
    const expanded = currentFile && currentFile.class === 'image'
    return (
      
        
          {this.renderViewer(currentFile)}
        
      
    )
  }
github cozy / cozy-ui / react / AppLinker / index.jsx View on Github external
static getOnClickHref(props, nativeAppIsAvailable) {
    const { slug, nativePath } = props
    let href = props.href
    let onClick = null
    const usingNativeApp = isMobileApp()
    const appInfo = NATIVE_APP_INFOS[slug]
    if (usingNativeApp) {
      if (nativeAppIsAvailable) {
        // If we are on the native app and the other native app is available,
        // we open the native app
        onClick = AppLinker.openNativeFromNative.bind(this, props)
        href = '#'
      } else {
        // If we are on a native app, but the other native app is not available
        // we open the web link, this is done by the href prop. We still
        // have to call the prop callback
        onClick = AppLinker.openWeb.bind(this, props)
      }
    } else if (isMobile() && appInfo) {
      // If we are on the "mobile web version", we try to open the native app
      // if it exists with an universal links. If it fails, we redirect to the web
github cozy / cozy-ui / react / Popup / index.jsx View on Github external
removeListeners() {
    window.removeEventListener('message', this.handleMessage)

    // rest of instructions only if popup is still opened
    if (this.popup.closed) return

    if (isMobileApp()) {
      this.popup.removeEventListener('loadstart', this.handleLoadStart)
      this.popup.removeEventListener('exit', this.handleClose)
    }
  }
github cozy / cozy-ui / react / Viewer / index.jsx View on Github external
// this `expanded` property makes the next/previous controls cover the displayed image
    const expanded = currentFile && currentFile.class === 'image'
    return (
      
        
          {this.renderViewer(currentFile)}
        
      
    )
  }
github cozy / cozy-ui / react / Viewer / index.jsx View on Github external
const currentFile = files[currentIndex]
    const fileCount = files.length
    const hasPrevious = currentIndex > 0
    const hasNext = currentIndex < fileCount - 1
    // this `expanded` property makes the next/previous controls cover the displayed image
    const expanded = currentFile && currentFile.class === 'image'
    return (
      
        
          {this.renderViewer(currentFile)}
        
      
    )
  }
github cozy / cozy-ui / react / SelectBox / SelectBox.jsx View on Github external
className={classNames(
          {
            [styles['select__overlay']]: showOverlay,
            [styles['select--autowidth']]: !fullwidth,
            [styles['select--disabled']]: disabled,
            [styles['select--fullwidth']]: fullwidth
          },
          className
        )}
        // react-select temporarily adds className to its innerComponents
        // but this behavior will soon be removed. For the moment, we
        // cancel it by setting it to empty string
        // needsclick is added only on iOS App since fastclik tries to handle
        // the click and catch the event.
        classNamePrefix={
          isIOSApp()
            ? `needsclick ${classNamePrefix ? classNamePrefix : ''}`
            : classNamePrefix
            ? classNamePrefix
            : ''
        }
        selectProps={{ name }}
      />
    )
  }
}