react-native-linking-controller
v0.0.3
Published
Manage actions that come from linking in React Native applications
Downloads
6
Readme
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