react-native-root-siblings
Advanced tools
Comparing version 3.1.4 to 3.1.5
135
index.js
import React, { Component, cloneElement } from 'react'; | ||
import { StyleSheet, View, AppRegistry } from 'react-native'; | ||
import StaticContainer from 'static-container'; | ||
import { Provider } from 'react-redux'; | ||
@@ -12,91 +11,91 @@ const styles = StyleSheet.create({ | ||
AppRegistry.setWrapperComponentProvider(function() { | ||
return function RootSiblingsWrapper(props) { | ||
return ( | ||
<View style={styles.container}> | ||
{props.children} | ||
<RootSiblings /> | ||
</View> | ||
); | ||
}; | ||
}); | ||
let uuid = 0; | ||
const triggers = []; | ||
class RootSiblings extends Component { | ||
_updatedSiblings = {}; | ||
_siblings = {}; | ||
_stores = {}; | ||
AppRegistry.setWrapperComponentProvider(function () { | ||
return class extends Component { | ||
static displayName = 'RootSiblingsWrapper'; | ||
constructor(props) { | ||
super(props); | ||
this._siblings = {}; | ||
triggers.push(this._update); | ||
} | ||
constructor(props) { | ||
super(props); | ||
this._siblings = {}; | ||
triggers.push(this._update); | ||
} | ||
componentWillUnmount() { | ||
triggers.splice(triggers.indexOf(this._update), 1); | ||
} | ||
componentWillUnmount() { | ||
triggers.splice(triggers.indexOf(this._update), 1); | ||
_update = (id, element, callback, store) => { | ||
const siblings = { ...this._siblings }; | ||
const stores = { ...this._stores }; | ||
if (siblings[id] && !element) { | ||
delete siblings[id]; | ||
delete stores[id]; | ||
} else if (element) { | ||
siblings[id] = element; | ||
stores[id] = store; | ||
} | ||
this._updatedSiblings[id] = true; | ||
this._siblings = siblings; | ||
this._stores = stores; | ||
this.forceUpdate(callback); | ||
}; | ||
_updatedSiblings = {}; | ||
_siblings = {}; | ||
_stores = {}; | ||
render() { | ||
const siblings = this._siblings; | ||
const stores = this._stores; | ||
const elements = []; | ||
Object.keys(siblings).forEach(key => { | ||
const element = siblings[key]; | ||
if (element) { | ||
const sibling = ( | ||
<StaticContainer key={`root-sibling-${key}`} shouldUpdate={!!this._updatedSiblings[key]}> | ||
{element} | ||
</StaticContainer> | ||
); | ||
_update = (id, element, callback, store) => { | ||
const siblings = { ...this._siblings }; | ||
const stores = { ...this._stores }; | ||
if (siblings[id] && !element) { | ||
delete siblings[id]; | ||
delete stores[id]; | ||
} else if (element) { | ||
siblings[id] = element; | ||
stores[id] = store; | ||
} | ||
this._updatedSiblings[id] = true; | ||
this._siblings = siblings; | ||
this._stores = stores; | ||
this.forceUpdate(callback); | ||
}; | ||
render() { | ||
const siblings = this._siblings; | ||
const stores = this._stores; | ||
const elements = []; | ||
Object.keys(siblings).forEach((key) => { | ||
const element = siblings[key]; | ||
if (element) { | ||
const sibling = ( | ||
<StaticContainer | ||
key={`root-sibling-${key}`} | ||
shouldUpdate={!!this._updatedSiblings[key]} | ||
> | ||
{element} | ||
</StaticContainer> | ||
); | ||
const store = stores[key]; | ||
elements.push(store ? ( | ||
const store = stores[key]; | ||
if (store) { | ||
const Provider = require('react-redux').Provider; | ||
elements.push( | ||
<Provider store={store} key={`root-sibling-${key}-provider`}> | ||
{sibling} | ||
</Provider> | ||
) : sibling); | ||
); | ||
} else { | ||
elements.push(sibling); | ||
} | ||
}); | ||
this._updatedSiblings = {}; | ||
return ( | ||
<View style={styles.container}> | ||
<StaticContainer shouldUpdate={false}> | ||
{this.props.children} | ||
</StaticContainer> | ||
{elements} | ||
</View> | ||
); | ||
} | ||
} | ||
}); | ||
this._updatedSiblings = {}; | ||
return elements; | ||
} | ||
}) | ||
} | ||
export default class RootSiblings { | ||
export default class RootSiblingManager { | ||
constructor(element, callback, store) { | ||
const id = uuid++; | ||
function update(element, callback, store) { | ||
triggers.forEach(function (trigger) { | ||
triggers.forEach(function(trigger) { | ||
trigger(id, element, callback, store); | ||
}); | ||
}; | ||
} | ||
function destroy (callback) { | ||
triggers.forEach(function (trigger) { | ||
function destroy(callback) { | ||
triggers.forEach(function(trigger) { | ||
trigger(id, null, callback); | ||
}); | ||
}; | ||
} | ||
@@ -103,0 +102,0 @@ update(element, callback, store); |
{ | ||
"version": "3.1.4", | ||
"name": "react-native-root-siblings", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:magicismight/react-native-root-siblings.git" | ||
}, | ||
"license": "MIT", | ||
"description": "react native root sibling elements manager", | ||
"dependencies": { | ||
"static-container": "^1.0.0", | ||
"react-redux": "*" | ||
}, | ||
"keywords": [ | ||
"react-component", | ||
"react-native", | ||
"ios", | ||
"android" | ||
] | ||
"version": "3.1.5", | ||
"name": "react-native-root-siblings", | ||
"repository": { | ||
"type": "git", | ||
"url": "git@github.com:magicismight/react-native-root-siblings.git" | ||
}, | ||
"license": "MIT", | ||
"description": "react native root sibling elements manager", | ||
"dependencies": { | ||
"static-container": "^1.0.0" | ||
}, | ||
"keywords": [ | ||
"react-component", | ||
"react-native", | ||
"ios", | ||
"android" | ||
] | ||
} |
@@ -20,3 +20,4 @@ ### react-native-root-siblings | ||
1. Create sibling element | ||
``` | ||
```js | ||
let sibling = new RootSiblings(<View | ||
@@ -26,2 +27,3 @@ style={{top: 0,right: 0,bottom: 0,left: 0,backgroundColor: 'red'}} | ||
``` | ||
This will create a View element cover all of your app elements, | ||
@@ -32,3 +34,4 @@ and returns a sibling instance. | ||
2. Update sibling element | ||
``` | ||
```js | ||
sibling.update(<View | ||
@@ -38,8 +41,11 @@ style={{top: 10,right: 10,bottom: 10,left: 10,backgroundColor: 'blue'}} | ||
``` | ||
This will update the sibling instance to a View with blue backgroundColor and cover the screen by `10` offset distance. | ||
3. Destroy sibling element | ||
``` | ||
```js | ||
sibling.destroy(); | ||
``` | ||
This will remove the sibling element. | ||
@@ -49,3 +55,3 @@ | ||
``` | ||
```js | ||
'use strict'; | ||
@@ -52,0 +58,0 @@ import React, { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Wildcard dependency
QualityPackage has a dependency with a floating version range. This can cause issues if the dependency publishes a new major version.
Found 1 instance in 1 package
1
8
100
0
157
8944
- Removedreact-redux@*
- Removed@types/use-sync-external-store@0.0.6(transitive)
- Removedreact@19.0.0(transitive)
- Removedreact-redux@9.2.0(transitive)
- Removeduse-sync-external-store@1.4.0(transitive)