Created
November 17, 2018 14:28
-
-
Save midoalone/e520b62e1b4bda05bb4a57b725e79f5f to your computer and use it in GitHub Desktop.
wiki.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import { FlatList, Text, View } from 'react-native' | |
// Styles | |
import { Button, Container, Header, Icon, Input, Item } from 'native-base' | |
export default class LaunchScreen extends Component { | |
state={ | |
data: [], | |
query: '', | |
loadingIcon: false | |
} | |
onTyping = (search) => { | |
fetch(`https://en.wikipedia.org/w/api.php?action=opensearch&format=json&search=${search}`) | |
.then(response => response.json()) | |
.then(result => this.setState({ | |
data: result[1] | |
})) | |
} | |
renderItem = ({item, index}) => ( | |
<View key={index}> | |
<Text>{item}</Text> | |
</View> | |
) | |
render () { | |
return ( | |
<Container> | |
<Header searchBar rounded> | |
<Item> | |
<Icon name="ios-search" /> | |
<Input placeholder="Search" onChangeText={(search) => { | |
this.onTyping(search) | |
}} /> | |
<Icon name="ios-people" /> | |
</Item> | |
<Button transparent> | |
<Text>Search</Text> | |
</Button> | |
</Header> | |
<FlatList | |
data={this.state.data} | |
renderItem={this.renderItem} | |
/> | |
</Container> | |
) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment