Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-native-external-display

mybigday7.4kMIT0.6.6TypeScript support: included

React Native view renderer in External Display

react-native, external-display, uiscene, native-module, native-ui-component, ios, android

readme

react-native-external-display

React Native view renderer on External Display. Also supports Multiple Scenes on iOS.

For Multiple Scenes usage on iOS, please read this documentation.

Installation

  • Add dependency with yarn add react-native-external-display
  • You may need to run react-native link react-native-external-display or autolinking.

Usage

Example

import React from 'react'
import ExternalDisplay, { useExternalDisplay } from 'react-native-external-display'

function App() {
  const screens = useExternalDisplay()

  return (
    <ExternalDisplay
      mainScreenStyle={{ flex: 1 }}
      fallbackInMainScreen
      screen={Object.keys(screens)[0]}
    >
      <View
        style={{
          flex: 1,
          justifyContent: 'center',
          alignItems: 'center',
          backgroundColor: '#333',
        }}
      >
        <Text style={{ color: 'red', fontSize: 40 }}>External Display</Text>
      </View>
    </ExternalDisplay>
  )
}

getScreens(): ScreenInfo

type Screen = {
  id: string,
  width: number,
  height: number,
  mirrored?: boolean,
}
type ScreenInfo = {
  [screenId: string]: Screen,
}

You need to use Screen size instead of Dimensions.get() if you want to know the external screen size.

useExternalDisplay(options?: ExternalDisplayOptions): ScreenInfo

A react hook to get ScreenInfo update.

type ExternalDisplayOptions = {
  onScreenConnect: Function,
  onScreenChange: Function,
  onScreenDisconnect: Function,
}

useScreenSize(): Screen

A react hook to get current used screen size. (rendered in <ExternalDisplay />)

It will get null if it rendered as fallback in main screen.

<ExternalDisplay />

Props (Extend ViewProps)

Prop Type Note
fallbackInMainScreen Boolean Render children in main screen if no detected external display target. It's useful if you don't want the component instances to be re-mount.
mainScreenStyle ViewProps.style Style of fallbackInMainScreen render children wrap view container.
screen String Render external display target, you can get screenId from ScreenInfo type

Events

Event Name Returns Notes
onScreenConnect ScreenInfo When an external monitor added
onScreenDisconnect ScreenInfo When an external monitor removed

License

MIT

changelog

Change Log

All notable changes to this project will be documented in this file. See Conventional Commits for commit guidelines.

0.6.6 (2024-09-01)

Bug Fixes

  • android: unnecessary methods in old arch (c88b8fe)
  • ios: new arch setup in podspec (9c9350c)
  • new arch codegen by unify NativeRNExternalDisplayEvent (88057a7)

0.6.5 (2024-07-16)

Bug Fixes

  • ios: remove subview in _subviews (abbf0eb)
  • ios: use synchronized for pointer array op to avoid possible crash (afccdea)

0.6.4 (2023-11-14)

Features

0.6.3 (2023-11-02)

Bug Fixes

  • android: skip display that no a presentation display (aa2142a)

0.6.2 (2023-10-18)

Bug Fixes

0.6.1 (2023-07-05)

Bug Fixes

  • ios: warnings of UIScene usage (01131c7)

0.6.0 (2023-06-30)

Bug Fixes

  • ios: touch gestures on created extra UIScene (#701) (6dbcaba)

0.6.0-rc.4 (2023-06-28)

Bug Fixes

  • ios: put RN_EXTERNAL_SCENE_TYPE_EXTERNAL default type if not enabled multiple scenes (cb4d229)

0.6.0-rc.3 (2023-06-28)

Features

  • ios: support Multiple UIScene for iPad targets (#693) (ab8c548)

0.6.0-rc.2 (2023-06-25)

Bug Fixes

  • ios: use RCTViewComponentView as external screen wrap view on new arch (6f0cedb)

0.6.0-rc.1 (2023-06-22)

Bug Fixes

  • ios: cleanup observer at invalidate (ca03e7d)

0.6.0-rc.0 (2023-06-22)

Features

0.5.18 (2022-10-22)

Bug Fixes

  • android: ScrollView is not working on external display (#578) (9b58849)

Features

  • ios: move podspec to root dir of package (3f0ac9a)

0.5.17 (2022-05-17)

Bug Fixes

  • android: connected screen not resume if host resumed (8a01beb)

0.5.16 (2022-02-13)

Bug Fixes

  • android: mount child view issue on switch display (95be339)

0.5.15 (2022-02-13)

Bug Fixes

  • android: call dismiss on destroy screen (84a7fdb)
  • android: scale on external display (#413) (90b1da6)

0.5.14 (2021-12-14)

Bug Fixes

  • android: clear subview on removeViewAt during lifecycle (395f557)

0.5.13 (2021-12-13)

Bug Fixes

  • android: do not refresh screen on host pause / resume if no external display connected (9a3413f)

0.5.12 (2021-11-11)

Bug Fixes

  • tvos: ignore availableModes check (76634ad)

0.5.11 (2021-11-11)

Features

  • ios: Support change screen mode to highest width mode (#375) (287d015)

0.5.10 (2021-07-29)

Bug Fixes

  • android: add missing removeLifecycleEventListener for RNExternalDisplayView (6789740)

0.5.9 (2021-05-28)

Features

0.5.8 (2021-01-26)

Bug Fixes

  • android: thread looper issue if JSI modules enabled (#230) (74ad50b)

0.5.6 (2020-12-12)

Bug Fixes

  • android: crash with accessibility enabled (#216) (bca12a8)

0.5.5 (2020-09-25)

Bug Fixes

  • ios: react dependency for support Xcode 12 (01fc079)

0.5.4 (2020-09-21)

Bug Fixes

  • android: ensure parent child is removed for fallbackInMainScreen (e62eaff)

0.5.3 (2020-09-21)

Bug Fixes

  • android: remove / add external view between onHostPause and onHostResume, closes #142 (711562f)

0.5.2 (2020-03-07)

Bug Fixes

  • ios: screen info initial constants (5b2ec75)

0.5.1 (2020-03-04)

Features

  • android: Log error when detected two or more RNExternalDisplayView to register the same screen id (7d10933)
  • ios: Log error when detected two or more RNExternalDisplayView to register the same screen id (ccabd0f)

0.5.0 (2020-03-02)

Bug Fixes

  • android: update build.gradle (236c5ab)

Features

  • android: update package name (63b547e)

0.4.2 (2020-03-02)

Bug Fixes

  • android: should check child count before removeViewAt for wrap view group (042d1f2)

0.4.1 (2020-03-02)

Bug Fixes

  • android: parent view group issue on change screen (76e732f)

0.4.0 (2020-03-02)

Features

  • js: expose scaled screen size depends on main screen (d565881)
  • js: implement useScreenSize hook (15bccc9)

0.3.1 (2020-03-01)

Features

  • js: add default options for useExternalDisplay (48b9cad)

0.3.0 (2020-02-29)

Features

  • js: implement useExternalDisplay hook (#5) (17792c6)

0.2.0 (2020-02-29)

Bug Fixes

  • android: Wrap new ReactViewGroup for target external screen view (44a3f49), closes #1
  • ios: Wrap new RCTView for target external screen view (41b6efc)

Features

  • ios: always call [super insertReactSubview], and render fallback depends on didUpdateReactSubviews (a0c2c43)
  • ios: call makeKeyAndVisible for main window after invalidateWindow (a8bbea2)
  • ios: implement RCTInvalidating method (e9c2ede)

0.1.6 (2020-02-28)

Features

  • ios: add tvos deployment target (a2faa45)

0.1.5 (2020-02-28)

Bug Fixes

  • ios: do not remove subview from superview on invalidate (ef093b7)

0.1.4 (2020-02-28)

Bug Fixes

  • ios: updateScreen after setFallbackInMainScreen (9b4f333)

0.1.3 (2020-02-28)

Note: Version bump only for package react-native-external-display

0.1.2 (2020-02-28)

Bug Fixes

0.1.1 (2020-02-28)

Bug Fixes

  • ios: wrap new UIViewController for external window (cb36491)