0.0.3 • Published 4 years ago

react-native-dual-screen v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

react-native-dual-screen

npm version Dependency Status devDependencies Status typings included npm

React Native package for dual screen devices support (Surface Duo). Surface Neo support is coming

Surface Duo Demo

Status

  • Android:
    • 10+
  • react-native:
    • supported versions ">= 0.60.5"

Installation

0. Setup Swift and Kotlin

  • Modify android/build.gradle:

    buildscript {
      ext {
        ...
    +   kotlinVersion = "1.3.50"
      }
    ...
    
      dependencies {
    +   classpath("org.jetbrains.kotlin:kotlin-gradle-plugin:${kotlinVersion}")
        ...

1. Install latest version from npm

$ yarn add react-native-dual-screen

2. Modify android:configChanges of your activity

android:configChanges="keyboard|keyboardHidden|orientation|screenSize|smallestScreenSize|screenLayout"

Example

import * as React from 'react'
import { View } from 'react-native'
import { RNDualScreenManager, Hinge } from 'react-native-dual-screen'

export default function App() {
  const [isDualMode, setDualMode] = useState(false)
    useEffect(() => {
        RNDualScreenManager.isDualMode().then((isDual: boolean) => {
            setDualMode(isDual)
        })

        RNDualScreenManager.addOnChangeListener((event) => {
            const isDual = event.isDualMode === 'true'
            if (isDualMode !== isDual) {
                setDualMode(isDual)
            }
        })
    })

    if (isDualMode) {
      return (
        <View style={{ flex: 1, flexDirection: 'row' }}>
          <View style={{ flex: 1 }}>
            <Text>Screen 1</Text>
          </View>
          <Hinge/>
          <View style={{ flex: 1 }}>
            <Text>Screen 2</Text>
          </View>
        </View>
      )
    }

    return (
      <View style={{ flex: 1 }}>
        <Text>Screen 1</Text>
      </View>  
    )
}

Reference

Documentation

Get the Surface Duo SDK

Use the Surface Duo emulator

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago