0.0.3 • Published 7 years ago

react-native-linking-controller v0.0.3

Weekly downloads
2
License
MIT
Repository
github
Last release
7 years ago

Build Status

react-native-linking-controller

Small library for manage actions that come from external urls. Created for more convenient work with Linking

Example

import React from 'react';
import {
    View,
    Linking
} from 'react-native';
import {
    setTheme,
} from 'react-native-material-kit';
import LinkingController from 'react-native-linking-controller';

const linkingActions = {
    //using default matcher: runs if url contains correct parameter `action`
    //Example: http://some.com?action=first-action
    'first-action': (action, context) => {
        dispatch(actions.security.setPasswordResetToken(action.params.token));
    },
    //custom matcher
    'another-action': {
        match: (url) => {
            //should return object that contains action params in case match url
            //false otherwise
        },
        action: (action, context) => {
            //do some staff
        }
    }
};

export default class App extends React.Component {
    //...
    componentDidMount() {
        //Possible actions context. Passed in second action parameter
        let actionsContext = this.context;
        let linkingController = new LinkingController(actionsContext);
        
        _.each(linkingActions, (callback, action) => {
            linkingController.registerAction(action, callback);
        });

        linkingController.bindToLinking(Linking);
    }
}

More information you can get in tests

License

MIT