Update with-webbrowser-redirect for new sdk

This commit is contained in:
Brent Vatne
2017-11-12 19:15:16 -08:00
parent 98c36b8d96
commit eb5a875a73
5 changed files with 1054 additions and 888 deletions

View File

@@ -1,18 +1,9 @@
import Expo, {
Constants,
WebBrowser,
} from 'expo';
import Expo, { Constants, WebBrowser } from 'expo';
import React from 'react';
import {
Button,
Linking,
StyleSheet,
Text,
View,
} from 'react-native';
import { Button, Linking, StyleSheet, Text, View } from 'react-native';
import qs from 'qs';
class App extends React.Component {
export default class App extends React.Component {
state = {
redirectData: null,
};
@@ -20,9 +11,7 @@ class App extends React.Component {
render() {
return (
<View style={styles.container}>
<Text style={styles.header}>
Redirect Example
</Text>
<Text style={styles.header}>Redirect Example</Text>
<Button
onPress={this._openWebBrowserAsync}
@@ -34,7 +23,7 @@ class App extends React.Component {
);
}
_handleRedirect = (event) => {
_handleRedirect = event => {
WebBrowser.dismissBrowser();
let query = event.url.replace(Constants.linkingUri, '');
@@ -45,38 +34,33 @@ class App extends React.Component {
data = null;
}
this.setState({redirectData: data});
}
this.setState({ redirectData: data });
};
_openWebBrowserAsync = async () => {
this._addLinkingListener();
let result = await WebBrowser.openBrowserAsync(
`https://backend-xxswjknyfi.now.sh//?linkingUri=${Constants.linkingUri}`
`https://backend-xxswjknyfi.now.sh/?linkingUri=${Constants.linkingUri}`
);
this._removeLinkingListener();
this.setState({ result });
}
};
_addLinkingListener = () => {
Linking.addEventListener('url', this._handleRedirect);
}
};
_removeLinkingListener = () => {
Linking.removeEventListener('url', this._handleRedirect);
}
};
_maybeRenderRedirectData = () => {
if (!this.state.redirectData) {
return;
}
return (
<Text>
{JSON.stringify(this.state.redirectData)}
</Text>
);
}
return <Text>{JSON.stringify(this.state.redirectData)}</Text>;
};
}
const styles = StyleSheet.create({
@@ -92,5 +76,3 @@ const styles = StyleSheet.create({
marginBottom: 25,
},
});
Expo.registerRootComponent(App);

View File

@@ -0,0 +1,18 @@
{
"expo": {
"name": "with-webbrowser-redirect",
"slug": "with-webbrowser-redirect",
"privacy": "public",
"sdkVersion": "22.0.0",
"version": "1.0.0",
"orientation": "portrait",
"primaryColor": "#cccccc",
"icon": "./assets/icons/app.png",
"loading": {
"icon": "./assets/icons/loading.png"
},
"ios": {
"supportsTablet": true
}
}
}

View File

@@ -1,21 +0,0 @@
{
"name": "with-webbrowser-redirect",
"description": "An empty new project",
"slug": "with-webbrowser-redirect",
"privacy": "public",
"sdkVersion": "17.0.0",
"version": "1.0.0",
"orientation": "portrait",
"primaryColor": "#cccccc",
"icon": "./assets/icons/app.png",
"loading": {
"icon": "./assets/icons/loading.png",
"hideExponentText": false
},
"packagerOpts": {
"assetExts": ["ttf", "mp4"]
},
"ios": {
"supportsTablet": true
}
}

View File

@@ -1,14 +1,11 @@
{
"name": "with-webbrowser-redirect",
"version": "0.0.0",
"description": "Hello Expo!",
"author": null,
"private": true,
"main": "main.js",
"main": "node_modules/expo/AppEntry.js",
"dependencies": {
"expo": "17.0.0",
"expo": "^22.0.0",
"qs": "^6.4.0",
"react": "16.0.0-alpha.6",
"react-native": "https://github.com/expo/react-native/archive/sdk-17.0.0.tar.gz"
"react": "16.0.0-beta.5",
"react-native": "https://github.com/expo/react-native/archive/sdk-22.0.2.tar.gz"
}
}

File diff suppressed because it is too large Load Diff