react-native-root-siblings
Advanced tools
Comparing version 1.2.0 to 1.2.1
@@ -13,65 +13,70 @@ import { StyleSheet, View, AppRegistry } from 'react-native'; | ||
const emitter = new EventEmitter(); | ||
let emitter = AppRegistry.rootSiblingsEmitter; | ||
// inject modals into app entry component | ||
const originRegister = AppRegistry.registerComponent; | ||
if (!(emitter instanceof EventEmitter)) { | ||
emitter = new EventEmitter(); | ||
// inject modals into app entry component | ||
const originRegister = AppRegistry.registerComponent; | ||
AppRegistry.registerComponent = function (appKey, getAppComponent) { | ||
const siblings = new Map(); | ||
const updates = new Set(); | ||
AppRegistry.registerComponent = function (appKey, getAppComponent) { | ||
const siblings = new Map(); | ||
const updates = new Set(); | ||
return originRegister(appKey, function () { | ||
const OriginAppComponent = getAppComponent(); | ||
return originRegister(appKey, function () { | ||
const OriginAppComponent = getAppComponent(); | ||
return class extends Component { | ||
static displayName = `Root(${appKey})`; | ||
return class extends Component { | ||
static displayName = `Root(${appKey})`; | ||
componentWillMount() { | ||
this._update = this._update.bind(this); | ||
emitter.addListener('siblings.update', this._update); | ||
}; | ||
componentWillMount() { | ||
this._update = this._update.bind(this); | ||
emitter.addListener('siblings.update', this._update); | ||
}; | ||
componentWillUnmount() { | ||
emitter.removeListener('siblings.update', this._update); | ||
siblings.clear(); | ||
updates.clear(); | ||
}; | ||
componentWillUnmount() { | ||
emitter.removeListener('siblings.update', this._update); | ||
siblings.clear(); | ||
updates.clear(); | ||
}; | ||
_update(id, element, callback) { | ||
if (siblings.has(id) && !element) { | ||
siblings.delete(id); | ||
} else { | ||
siblings.set(id, element); | ||
} | ||
updates.add(id); | ||
this.forceUpdate(callback); | ||
}; | ||
_update(id, element, callback) { | ||
if (siblings.has(id) && !element) { | ||
siblings.delete(id); | ||
} else { | ||
siblings.set(id, element); | ||
} | ||
updates.add(id); | ||
this.forceUpdate(callback); | ||
}; | ||
render() { | ||
const elements = []; | ||
siblings.forEach((element, id) => { | ||
elements.push( | ||
<StaticContainer | ||
key={`root-sibling-${id}`} | ||
shouldUpdate={updates.has(id)} | ||
> | ||
{element} | ||
</StaticContainer> | ||
render() { | ||
const elements = []; | ||
siblings.forEach((element, id) => { | ||
elements.push( | ||
<StaticContainer | ||
key={`root-sibling-${id}`} | ||
shouldUpdate={updates.has(id)} | ||
> | ||
{element} | ||
</StaticContainer> | ||
); | ||
}); | ||
updates.clear(); | ||
return ( | ||
<View style={styles.container}> | ||
<StaticContainer shouldUpdate={false}> | ||
<OriginAppComponent {...this.props} /> | ||
</StaticContainer> | ||
{elements} | ||
</View> | ||
); | ||
}); | ||
updates.clear(); | ||
return ( | ||
<View style={styles.container}> | ||
<StaticContainer shouldUpdate={false}> | ||
<OriginAppComponent {...this.props} /> | ||
</StaticContainer> | ||
{elements} | ||
</View> | ||
); | ||
}; | ||
}; | ||
}; | ||
}); | ||
}; | ||
}); | ||
}; | ||
AppRegistry.rootSiblingsEmitter = emitter; | ||
} | ||
export default emitter; |
{ | ||
"version": "1.2.0", | ||
"version": "1.2.1", | ||
"name": "react-native-root-siblings", | ||
@@ -4,0 +4,0 @@ "repository": { |
Sorry, the diff of this file is not supported yet
100
50710