mirror of
https://github.com/zhigang1992/examples.git
synced 2026-01-12 22:47:03 +08:00
Update with-webbrowser-redirect for new sdk
This commit is contained in:
@@ -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);
|
||||
18
with-webbrowser-redirect/app/app.json
Normal file
18
with-webbrowser-redirect/app/app.json
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -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
Reference in New Issue
Block a user