# rn-root-siblings **Repository Path**: jack-yao/rn-root-siblings ## Basic Information - **Project Name**: rn-root-siblings - **Description**: No description available - **Primary Language**: JavaScript - **License**: MIT - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2021-06-09 - **Last Updated**: 2021-06-09 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ``` 原作者版本1.2.1,仓库传送门git@github.com:magicismight/react-native-root-siblings.git 在原作者的基础上,仅修改了AppRegistryInjection.js中的EventEmitter出处,因RN0.48版本变动。 以下内容完全来自原作者,除模块名变化外,使用方法无变化 ``` --- ### react-native-root-siblings --- Add sibling elements after your app root element. The created sibling elements are above the rest of your app elements. This can be used to create a `Modal` component or something should be over your app. ### Add it to your project Run `npm install react-native-root-siblings --save` ### USAGE This library can add element above the root app component registered by `AppRegistry.registerComponent`. 1. Create sibling element ``` let sibling = new RootSiblings(); ``` This will create a View element cover all of your app elements, and returns a sibling instance. You can create a sibling anywhere inside your react native code. 2. Update sibling element ``` sibling.update(); ``` This will update the sibling instance to a View with blue backgroundColor and cover the screen by `10` offset distance. 3. Destroy sibling element ``` sibling.destroy(); ``` This will remove the sibling element. ### EXAMPLE ``` 'use strict'; import React, { AppRegistry, View, Component, TouchableHighlight, StyleSheet, Text } from 'react-native'; import Dimensions from 'Dimensions'; // Import library there,it will wrap everything registered by AppRegistry.registerComponent // And add or remove other elements after the root component import RootSiblings from 'react-native-root-siblings'; var id = 0; var elements = []; class SiblingsExample extends Component{ addSibling = () => { let sibling = new RootSiblings( I`m No.{id} ); id++; elements.push(sibling); }; destroySibling = () => { let lastSibling = elements.pop(); lastSibling && lastSibling.destroy(); }; updateSibling = () => { let lastId = elements.length - 1; lastId >= 0 && elements[lastId].update( I`m No.{lastId} : {Math.random()} ); }; render() { return Add element Destroy element Update element ; } } AppRegistry.registerComponent('SiblingsExample', () => SiblingsExample); var styles = StyleSheet.create({ container: { flex: 1, alignItems: 'center', justifyContent: 'center', backgroundColor: 'green', }, button: { borderRadius: 4, padding: 10, marginLeft: 10, marginRight: 10, backgroundColor: '#ccc', borderColor: '#333', borderWidth: 1, }, buttonText: { color: '#000' }, sibling: { left: 0, height: 20, width: Dimensions.get('window').width / 2, backgroundColor: 'blue', opacity: 0.5 } }); ``` ![screen shoot](./Examples/screen-shoot.gif) ### RUN EXAMPLE 1. fork this repository 2. change dictionary to `Examples` 3. run `npm i`