Skip to content

Commit 2152b0e

Browse files
committed
added react native modal and show episodes list
1 parent a2ab9db commit 2152b0e

File tree

3 files changed

+70
-5
lines changed

3 files changed

+70
-5
lines changed

package-lock.json

+17
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"react": "16.8.3",
1313
"react-native": "0.59.10",
1414
"react-native-gesture-handler": "1.3.0",
15+
"react-native-modal": "11.3.1",
1516
"react-native-reanimated": "1.1.0",
1617
"react-native-ui-kitten": "4.2.0-beta.1",
1718
"react-navigation": "3.11.1",

src/HomeScreen.js

+52-5
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import {
88
Animated,
99
Image
1010
} from 'react-native';
11+
import Modal from 'react-native-modal'
1112
import { Text } from 'react-native-ui-kitten'
1213
import { SafeAreaView } from 'react-navigation'
13-
import { FlatList, TouchableOpacity } from 'react-native-gesture-handler';
14+
import { FlatList } from 'react-native-gesture-handler';
1415

1516
const WINDOW_WIDTH = Dimensions.get('window').width
1617
const WINDOW_HEIGHT = Dimensions.get('window').height
@@ -32,7 +33,8 @@ class HomeScreen extends Component {
3233
{ title: "Breaking Bad", imageUrl: "https://www.thetvdb.com/banners/_cache/fanart/original/81189-1.jpg" },
3334
],
3435
activeImage: null,
35-
showCloseIcon: false
36+
showCloseIcon: false,
37+
isModalVisible: false
3638
}
3739

3840
componentWillMount() {
@@ -42,6 +44,48 @@ class HomeScreen extends Component {
4244
this.dimensions = new Animated.ValueXY()
4345
}
4446

47+
_renderEpisodeItem = ({ item, index }) => {
48+
const { title, imageUrl } = item
49+
50+
return (
51+
<View style={{ flexDirection: 'row', marginBottom: 10 }} >
52+
<Image style={{ height: 100, width: 100, borderRadius: 12 }} source={{ uri: imageUrl }} />
53+
<Text style={{ marginLeft: 20, marginTop: 8 }} category="h6" >{title}</Text>
54+
55+
<Text
56+
style={{ position: 'absolute', right: 0, marginTop: 12 }}
57+
category="h7" >$9.87</Text>
58+
</View>
59+
)
60+
}
61+
62+
_showModal() {
63+
console.log("modal shown", this.state.isModalVisible);
64+
65+
return (
66+
<View style={{ flex: 1 }}>
67+
<Modal
68+
style={{ margin: 0, justifyContent: 'flex-end' }}
69+
isVisible={this.state.isModalVisible}
70+
deviceHeight={WINDOW_HEIGHT / 2}
71+
deviceWidth={WINDOW_WIDTH}
72+
>
73+
<View style={{ height: WINDOW_HEIGHT / 1.8, backgroundColor: 'white' }}>
74+
<View style={{ marginLeft: 20, marginRight: 20, marginTop: 20 }}>
75+
<Text style={{ marginBottom: 25 }} category="h4">Season 1 Episodes</Text>
76+
<FlatList
77+
data={this.state.images}
78+
keyExtractor={this._keyExtractor}
79+
renderItem={this._renderEpisodeItem}
80+
/>
81+
{this._showCloseIcon()}
82+
</View>
83+
</View>
84+
</Modal>
85+
</View>
86+
)
87+
}
88+
4589
_openImage = (index) => {
4690
const ref = this.allImagesRefs[index]
4791
ref.measure((x, y, width, height, pageX, pageY) => {
@@ -84,6 +128,7 @@ class HomeScreen extends Component {
84128
})
85129
]).start(() => {
86130
this.setState({ showCloseIcon: true })
131+
this.setState({ isModalVisible: true })
87132
})
88133
})
89134
})
@@ -118,6 +163,7 @@ class HomeScreen extends Component {
118163

119164
_closeImage = () => {
120165
this.setState({ showCloseIcon: false })
166+
this.setState({ isModalVisible: false })
121167
Animated.parallel([
122168
Animated.timing(this.position.x, {
123169
toValue: this.oldPosition.x,
@@ -182,9 +228,10 @@ class HomeScreen extends Component {
182228
source={{ uri: this.state.activeImage ? this.state.activeImage.imageUrl : null }}
183229
>
184230
</Animated.Image>
185-
{this._showCloseIcon()}
231+
186232
</View>
187233
</View>
234+
{this._showModal()}
188235
</SafeAreaView>
189236
)
190237
}
@@ -221,9 +268,9 @@ const styles = StyleSheet.create({
221268
closeIcon: {
222269
position: 'absolute',
223270
right: 20,
224-
top: 40,
271+
top: 20,
225272
height: 32,
226273
width: 32,
227-
tintColor: 'white'
274+
tintColor: 'red'
228275
}
229276
});

0 commit comments

Comments
 (0)