React Nativeは全くの初心者です。
WebViewを使っていわゆるガワネイティブを作ろうとしています。
Webサイトを読み込む際、通信エラー等を拾ってエラーを出そうとしていますが、
下記コードだと通信エラーでなくてもエラーのアラートが出てしまいます。
エラーの場合のみアラートを出したいのですが、原因がわかりますでしょうか。
該当のソースコード
js
1import React, {Component} from 'react'; 2import { Platform, StyleSheet, Text, View, Alert, ActivityIndicator, BackHandler, Linking } from 'react-native'; 3import { WebView } from 'react-native'; 4import { withSafeArea } from 'react-native-safe-area'; 5 6type Props = {}; 7const SafeAreaView = withSafeArea(View, 'margin', 'all') 8export default class App extends Component<Props> { 9 10 constructor() { 11 super(); 12 } 13 14 render() { 15 return ( 16 <SafeAreaView style={styles.container}> 17 <WebView 18 source={{uri: 'https://google.co.jp'}} 19 onMessage={(event) => Linking.openURL( event.nativeEvent.data )} 20 onError={Alert.alert('通信エラーです。')} 21 style={styles.content} 22 /> 23 </SafeAreaView> 24 ); 25 } 26} 27 28const styles = StyleSheet.create({ 29 container: { 30 flex: 1, 31 }, 32 content: { 33 flex: 1, 34 }, 35})
バージョン
react-native-cli: 2.0.1
react-native: 0.57.3
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/10/20 05:51
2018/10/20 05:54