├── .gitignore
├── .jshintrc
├── src
├── index.js
└── meteorSwitch.js
├── package.json
├── LICENSE
└── README.md
/.gitignore:
--------------------------------------------------------------------------------
1 | npm-debug.log
--------------------------------------------------------------------------------
/.jshintrc:
--------------------------------------------------------------------------------
1 | {
2 | "esnext": true
3 | }
4 |
--------------------------------------------------------------------------------
/src/index.js:
--------------------------------------------------------------------------------
1 | import meteorSwitch from './meteorSwitch';
2 |
3 | module.exports = {
4 | meteorSwitch: meteorSwitch
5 | };
--------------------------------------------------------------------------------
/package.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "react-native-meteor-router-flux",
3 | "version": "1.1.0",
4 | "description": "Full Meteor Client for React Native - Plugin for react-native-router-flux",
5 | "main": "src/index.js",
6 | "scripts": {
7 | "test": "echo \"Error: no test specified\" && exit 1"
8 | },
9 | "repository": {
10 | "type": "git",
11 | "url": "git+https://github.com/inProgress-team/react-native-meteor-router-flux.git"
12 | },
13 | "keywords": [
14 | "react-component",
15 | "ddp",
16 | "meteor",
17 | "react",
18 | "react-native",
19 | "ios",
20 | "android",
21 | "react-native-router-flux"
22 | ],
23 | "author": "Théo Mathieu",
24 | "license": "MIT",
25 | "bugs": {
26 | "url": "https://github.com/inProgress-team/react-native-meteor-router-flux/issues"
27 | },
28 | "homepage": "https://github.com/inProgress-team/react-native-meteor-router-flux#readme",
29 | "dependencies": {
30 |
31 | }
32 | }
33 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2015 inProgress
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
23 |
--------------------------------------------------------------------------------
/src/meteorSwitch.js:
--------------------------------------------------------------------------------
1 | import React, { Component } from 'react';
2 | import { DefaultRenderer, Actions } from 'react-native-router-flux';
3 | import Meteor from 'react-native-meteor';
4 |
5 | module.exports = (getMeteorData) => {
6 |
7 | class RouterFluxSwitch extends Component {
8 | constructor(props){
9 | super(props);
10 | this.state = {};
11 | }
12 | componentWillMount() {
13 | this.onChange = (props)=>{
14 |
15 | const hasNewProps = !!props;
16 |
17 | props = props && props.name ? props : this.props;
18 |
19 | const navState = props.navigationState;
20 | const selector = props.selector || console.error("selector should be defined");
21 | const selectedKey = selector(getMeteorData(), props) || console.error("selector should return key");
22 | const selected = navState.children.filter(el=>el.sceneKey==selectedKey) || console.error("key="+selectedKey+" doesn't exist");
23 | const navigationState = selected[0] || console.error("Cannot find scene with key="+selectedKey);
24 |
25 | if (!navigationState || navigationState.key != navState.children[navState.index].key){
26 | Actions[selectedKey]();
27 | }
28 |
29 | if(hasNewProps) {
30 | this.setState({navigationState});
31 | }
32 |
33 | };
34 |
35 | this.onChange(this.props);
36 | Meteor.getData().onChange(()=>{
37 | this.onChange();
38 | });
39 | }
40 | componentWillReceiveProps(props) {
41 | this.onChange(props);
42 | }
43 | componentWillUnmount() {
44 | Meteor.getData().offChange(this.onChange);
45 | }
46 | render(){
47 | if (this.state.navigationState){
48 | return ;
49 | }
50 |
51 | return null;
52 | }
53 | }
54 |
55 | return RouterFluxSwitch;
56 | }
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | [](https://badge.fury.io/gh/inProgress-team%2Freact-native-meteor-router-flux)
2 | [](http://badge.fury.io/js/react-native-meteor-router-flux)
3 | [](https://david-dm.org/inProgress-team/react-native-meteor-router-flux)
4 | [](https://david-dm.org/inProgress-team/react-native-meteor-router-flux#info=devDependencies)
5 | [![MIT][license-badge]][license]
6 | [![bitHound Score][bithound-badge]][bithound]
7 |
8 | [bithound-badge]: https://www.bithound.io/github/inProgress-Team/react-native-meteor-router-flux/badges/score.svg
9 | [bithound]: https://www.bithound.io/github/inProgress-Team/react-native-meteor-router-flux
10 | [license-badge]: https://img.shields.io/dub/l/vibe-d.svg
11 | [license]: https://github.com/inProgress-team/react-native-meteor-router-flux/blob/master/LICENSE
12 |
13 | # DEPRECATED
14 |
15 | This plugin is deprecated since react-native-meteor createContainer works with react-native-router-flux Switch component (see https://github.com/inProgress-team/react-native-meteor/blob/master/README.md#react-native-router-flux) for informations
16 |
17 |
18 | # react-native-meteor-router-flux
19 |
20 | Plugin for [react-native-meteor](https://github.com/inProgress-team/react-native-meteor).
21 |
22 | [Custom scene renderer](https://github.com/aksonov/react-native-router-flux#switch-new-feature) which allows to select tab scene to show depending from app state. It could be useful for authentication, restricted scenes, etc.
23 |
24 | ## Install
25 |
26 | npm i --save react-native-meteor-router-flux@latest
27 |
28 |
29 | ## Example usage
30 |
31 | ```javascript
32 |
33 | 'use strict';
34 |
35 | import React, { Component } from 'react-native';
36 | import { Actions, Scene, Router } from 'react-native-router-flux';
37 | import Meteor from 'react-native-meteor';
38 | import { meteorSwitch } from 'react-native-meteor-router-flux';
39 |
40 | export default class RouterContainer extends Component {
41 | render () {
42 |
43 | const getMeteorData = ()=>{
44 | return {
45 | connected: Meteor.status().connected,
46 | user: Meteor.user(),
47 | loggingIn: Meteor.loggingIn()
48 | }
49 | };
50 |
51 | const selector = (data, props) => {
52 | if(!data.connected || data.loggingIn) {
53 | return "loading";
54 | } else if (!data.user) {
55 | return "login";
56 | } else {
57 | return "loggedIn";
58 | }
59 |
60 | };
61 |
62 | const scenes = Actions.create(
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 | );
73 |
74 |
75 | return (
76 |
77 | );
78 | }
79 | }
80 |
81 | ```
82 |
83 | Pull Requests are welcome ! :)
84 |
--------------------------------------------------------------------------------