質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.46%
React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

Q&A

0回答

417閲覧

React NativeにおけるReact Navigationについて

howareyou1245

総合スコア20

React Native

React Nativeは、ネイティブモバイルアプリ(iOS/Android)を作成できるJavaScriptフレームワークです。Reactと同じ設計のため、宣言的なコンポーネントでリッチなUIを開発することが可能です。

iOS

iOSとは、Apple製のスマートフォンであるiPhoneやタブレット端末のiPadに搭載しているオペレーションシステム(OS)です。その他にもiPod touch・Apple TVにも搭載されています。

React.js

Reactは、アプリケーションのインターフェースを構築するためのオープンソースJavaScriptライブラリです。

0グッド

0クリップ

投稿2020/04/29 14:36

下記ソースコードを実行したいです。
内容としては、MainページとArchiveページの遷移を行うだけの単純なものです。
まず、Mainページ単体を表示してみたところ、WebページとiPhone実機にて正常に表示できました。
Archiveページ単体はstateが必須なので表示確認はできておりません。

Main単体では動きますが、Navigationを入れるとヘッダー部分以外なにも表示されなくなってしまいます。(Web,iPhoneともに)
特にエラーも表示されていないため、途方に暮れています。
なにか解決策はありますでしょうか。

React

1import React, { Component } from 'react'; 2import { StyleSheet, Text, View,Button,TouchableOpacity,FlatList,Image,Dimensions,ActivityIndicator,Animated,Easing,AsyncStorage,StatusBar } from 'react-native'; 3import { createAppContainer} from 'react-navigation'; 4import { createStackNavigator } from 'react-navigation-stack' 5 6class Archive extends Component { 7 8 static navigationOptions = { 9 title:"ストックした記事", 10 headerTintColor:"white", 11 headerBackTitleStyle:{color:"white"}, 12 headerStyle:{backgroundColor:"#00aced"}, 13 } 14 15 constructor() { 16 super() 17 this.state = { 18 threads:[] 19 } 20 } 21 22 componentDidMount() { 23 this.getData() 24 } 25 26 getData() { 27 AsyncStorage.getAllKeys((err,keys) => { 28 if(err){ 29 console.error(err) 30 return false 31 } else { 32 AsyncStorage.multiGet(keys, (err,data) => { 33 threads = data.map((i) => { 34 return JSON.parse(i[1]) 35 }) 36 this.setState({threads}) 37 return true 38 }) 39 } 40 }) 41 } 42 43 render() { 44 const {threads} = this.state 45 const {width} = Dimensions.get("window") 46 return ( 47 <View style={{ 48 flexDirection:"row",width:"100%" 49 }} > 50 <FlatList data={threads} renderItem={({item}) => { 51 return ( 52 <View style={{flexDirection:"row",width:"100%",borderBottomWidth:2,borderColor:"#f5f5f5"}} > 53 <Image style={{width:50,height:50}} source={{uri:item.thumbnail}} /> 54 <View style={{width: width-50}} > 55 <View style={{flexDirection:"column"}} > 56 <Text style={{color:"#000"}}>{item.title}</Text> 57 <Text style={{color:"#ababab",fontSize:10}}>{item.domain}</Text> 58 </View> 59 </View> 60 </View> 61 ) 62 }} /> 63 </View> 64 ) 65 } 66} 67 68class Spining extends Component { 69 constructor() { 70 super() 71 this.state = { 72 degree: new Animated.Value(0) 73 } 74 } 75 76 componentDidMout() { 77 this.animated() 78 } 79 80 componentWillUnmount() { 81 this.animated = () => { 82 return false 83 } 84 } 85 86 animated() { 87 Animated.timing( 88 this.state.degree, {toValue:1,duration:4000,easing:Easing.linear} 89 ).start( 90 () => { 91 this.setState({degree:new Animated.Value(0)}) 92 this.animated() 93 } 94 )//start 95 } 96 97 render() { 98 const {degree} = this.state 99 const _degree = degree.interpolate( { 100 inputRange:[0,1], 101 outputRange:["0deg","360deg"] 102 }) 103 104 return ( 105 <View> 106 <Animated.Image 107 source={require("./assets/cat.png")} 108 style={{transform:[{rorate:_degree}]}} 109 /> 110 </View> 111 ) 112 } 113} 114 115class Main extends Component { 116 static navigationOptions = ({navigation}) => ({ 117 title: "新着記事", 118 headerTintColor:"white", 119 headerBackTitleStyle:{color:"white"}, 120 headerStyle:{backgroundColor:"#00aced"}, 121 headerRight: () => 122 <TouchableOpacity style={{paddingRight:8}} 123 onPress={() => {navigation.navigate('Archive')}}> 124 <Image source={require("./assets/cat.png")} style={{ 125 "height":25,"width":25 126 }}/> 127 </TouchableOpacity> 128 }) 129 130 constructor() { 131 super() 132 this.state = { 133 isLoading:true, 134 threads:[], 135 opacity: new Animated.Value(0), 136 fontSize: new Animated.Value(0) 137 } 138 } 139 140 UNSAFE_componentWillMount() { 141 fetch("https://www.reddit.com/r/newsokur/hot.json") 142 .then((response) => response.json()) 143 .then((responseJson) => { 144 let threads = responseJson.data.children 145 threads = threads.map ( i => { 146 i.key = i.data.url 147 return i 148 }) 149 this.setState({threads:threads,isLoading:false}) 150 }) 151 .catch((error) => { 152 console.error(error) 153 }) 154 } 155 156 animate() { 157 158 Animated.timing( 159 this.state.opacity, 160 { 161 toValue:1, 162 duration:1000 163 } 164 ).start() 165 166 Animated.spring(this.state.fontSize, 167 { 168 toValue:1, 169 friction:1 170 } 171 ).start() 172 173 } 174 175 save({data}) { 176 AsyncStorage.setItem(data["title"],JSON.stringify(data),(err)=> { 177 if(err){ 178 console.error(err) 179 return false 180 } else { 181 return true 182 } 183 }) 184 } 185 186 render() { 187 const {threads,isLoading,opacity,fontSize} = this.state 188 const {width} = Dimensions.get("window") 189 const _fontSize = fontSize.interpolate( { 190 inputRange:[0,1], 191 outputRange:[0,12] 192 }) 193 194 195 if(!isLoading) 196 this.animate() 197 198 return ( 199 <View style={{justifyContent:"center",alignItems:"center"}}> 200 {isLoading 201 ? <ActivityIndicator/> 202 : <Animated.View style={{opacity:opacity}}> 203 <FlatList data={threads} renderItem={({item}) => { 204 return ( 205 <View style={{flexDirection:"row",width:"100%"}}> 206 <Image style={{width:50,height:50}} source={{uri:item.data.thumbnail}} /> 207 <View style={{width:width-50}}> 208 <View style={{flexDirection:"column"}}> 209 <Animated.Text style={{fontSize:_fontSize}}> 210 {item.data.title} 211 </Animated.Text> 212 <Text style={{color:"#ababab",fontSize:10}}> 213 {item.data.domain} 214 </Text> 215 <Button onPress={() => {this.save(item)}} title={"ストック"}/> 216 </View> 217 </View> 218 </View> 219 ) 220 }}/> 221 </Animated.View> 222 } 223 224 </View> 225 ) 226 } 227 228} 229 230 231const Appnavigation = createAppContainer(createStackNavigator( 232 { 233 Main:{screen:Main}, 234 Archive:{screen:Archive}, 235 }, 236 { 237 initialRouteName: "Main" 238 } 239)) 240 241 242export default class App extends Component { 243 constructor(props) { 244 super(props) 245 } 246 247 render() { 248 return ( 249 <View> 250 <StatusBar barStyle="light-content"/> 251 <Appnavigation/> 252 </View> 253 ) 254 } 255}

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

まだ回答がついていません

会員登録して回答してみよう

アカウントをお持ちの方は

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.46%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問