Browse Source

Add CocktailDetails screen to playground app

Will be used for shared element transition showcase
Guy Carmeli 5 years ago
parent
commit
0b9550f8cc

+ 6
- 0
playground/src/assets/cocktails.js View File

3
     id: '1',
3
     id: '1',
4
     name: "Negroni",
4
     name: "Negroni",
5
     image: require("../../img/cocktails/negroni.jpg"),
5
     image: require("../../img/cocktails/negroni.jpg"),
6
+    color: '#e00001',
6
     ingredients: [
7
     ingredients: [
7
       {
8
       {
8
         name: 'Gin',
9
         name: 'Gin',
22
     id: '2',
23
     id: '2',
23
     name: "Last Word",
24
     name: "Last Word",
24
     image: require("../../img/cocktails/lastWord.jpg"),
25
     image: require("../../img/cocktails/lastWord.jpg"),
26
+    color: '#c7cfb7',
25
     ingredients: [
27
     ingredients: [
26
       {
28
       {
27
         name: 'Gin',
29
         name: 'Gin',
41
     id: '3',
43
     id: '3',
42
     name: "Basil Smash",
44
     name: "Basil Smash",
43
     image: require("../../img/cocktails/cucumberBasilSmash.jpg"),
45
     image: require("../../img/cocktails/cucumberBasilSmash.jpg"),
46
+    color: '#9dd888',
44
     ingredients: [
47
     ingredients: [
45
       {
48
       {
46
         name: 'Gin',
49
         name: 'Gin',
59
     id: '4',
62
     id: '4',
60
     name: "Bloody Marry",
63
     name: "Bloody Marry",
61
     image: require("../../img/cocktails/bloodyMarry.jpg"),
64
     image: require("../../img/cocktails/bloodyMarry.jpg"),
65
+    color: '#e73e05',
62
     ingredients: [
66
     ingredients: [
63
       {
67
       {
64
         name: 'Vodka',
68
         name: 'Vodka',
94
     id: '5',
98
     id: '5',
95
     name: 'Gimlet',
99
     name: 'Gimlet',
96
     image: require('../../img/cocktails/gimlet.jpg'),
100
     image: require('../../img/cocktails/gimlet.jpg'),
101
+    color: '#d3d6cf',
97
     ingredients: [
102
     ingredients: [
98
       {
103
       {
99
         name: 'Gin',
104
         name: 'Gin',
113
     id: '6',
118
     id: '6',
114
     name: 'French Martini',
119
     name: 'French Martini',
115
     image: require('../../img/cocktails/frenchMartini.jpg'),
120
     image: require('../../img/cocktails/frenchMartini.jpg'),
121
+    color: '#c03500',
116
     ingredients: [
122
     ingredients: [
117
       {
123
       {
118
         name: 'Vodka',
124
         name: 'Vodka',

+ 1
- 0
playground/src/screens/Screens.js View File

7
 
7
 
8
 module.exports = {
8
 module.exports = {
9
   Buttons: 'Buttons',
9
   Buttons: 'Buttons',
10
+  CocktailDetailsScreen: 'CocktailDetailsScreen',
10
   CocktailsListScreen: 'CocktailsListScreen',
11
   CocktailsListScreen: 'CocktailsListScreen',
11
   ContextScreen: 'ContextScreen',
12
   ContextScreen: 'ContextScreen',
12
   ExternalComponent: 'ExternalComponent',
13
   ExternalComponent: 'ExternalComponent',

+ 1
- 0
playground/src/screens/index.js View File

12
 
12
 
13
 function registerScreens() {
13
 function registerScreens() {
14
   Navigation.registerComponent(Screens.Alert, () => require('./Alert'));
14
   Navigation.registerComponent(Screens.Alert, () => require('./Alert'));
15
+  Navigation.registerComponent(Screens.CocktailDetailsScreen, () => require('./sharedElementTransition/CocktailDetailsScreen'));
15
   Navigation.registerComponent(Screens.CocktailsListScreen, () => require('./sharedElementTransition/CocktailsList'));
16
   Navigation.registerComponent(Screens.CocktailsListScreen, () => require('./sharedElementTransition/CocktailsList'));
16
   Navigation.registerComponent(Screens.EventsOverlay, () => require('./StaticLifecycleOverlay'));
17
   Navigation.registerComponent(Screens.EventsOverlay, () => require('./StaticLifecycleOverlay'));
17
   Navigation.registerComponent(Screens.EventsScreen, () => require('./StaticEventsScreen'));
18
   Navigation.registerComponent(Screens.EventsScreen, () => require('./StaticEventsScreen'));

+ 46
- 0
playground/src/screens/sharedElementTransition/CocktailDetailsScreen.js View File

1
+const React = require('react');
2
+const { Component } = require('react');
3
+const { SafeAreaView, FlatList, View, Image, Text, StyleSheet } = require('react-native');
4
+
5
+class CocktailDetailsScreen extends Component {
6
+  render() {
7
+    return (
8
+      <View style={styles.root}>
9
+        <View style={[styles.header, {backgroundColor: this.props.color}]}>
10
+          <Text style={styles.title}>{this.props.name}</Text>
11
+        </View>
12
+        <Image
13
+          source={this.props.image}
14
+          style={styles.image}
15
+          />
16
+      </View>
17
+    );
18
+  }
19
+}
20
+
21
+module.exports = CocktailDetailsScreen;
22
+const SIZE = 120;
23
+const HEADER = 150;
24
+const styles = StyleSheet.create({
25
+  root: {
26
+    
27
+  },
28
+  header: {
29
+    height: HEADER,
30
+    width: '100%',
31
+    flexDirection: 'column-reverse'
32
+  },
33
+  title: {
34
+    fontSize: 32,
35
+    color: 'whitesmoke',
36
+    marginLeft: 24,
37
+    marginBottom: 16
38
+  },
39
+  image: {
40
+    height: SIZE,
41
+    width: SIZE,
42
+    position: 'absolute',
43
+    right: 24,
44
+    top: HEADER / 2
45
+  }
46
+});

+ 13
- 8
playground/src/screens/sharedElementTransition/CocktailsList.js View File

1
 const React = require('react');
1
 const React = require('react');
2
 const { Component } = require('react');
2
 const { Component } = require('react');
3
-const { SafeAreaView, FlatList, View, Image, Text, StyleSheet } = require('react-native');
4
-const { Navigation } = require('react-native-navigation');
3
+const { SafeAreaView, TouchableOpacity, FlatList, View, Image, Text, StyleSheet } = require('react-native');
4
+const Navigation = require('../../services/Navigation');
5
 const { slice } = require('lodash');
5
 const { slice } = require('lodash');
6
+const Screens = require('../Screens')
6
 const data = require('../../assets/cocktails').default;
7
 const data = require('../../assets/cocktails').default;
7
 
8
 
8
 class CocktailsList extends Component {
9
 class CocktailsList extends Component {
16
     }
17
     }
17
   }
18
   }
18
 
19
 
19
-  constructor(props) {
20
-    super(props);
21
-  }
22
-
23
   render() {
20
   render() {
24
     return (
21
     return (
25
       <FlatList
22
       <FlatList
35
   separatorComponent = () => <View style={styles.separator} />;
32
   separatorComponent = () => <View style={styles.separator} />;
36
 
33
 
37
   renderItem = ({ item }) => (
34
   renderItem = ({ item }) => (
38
-    <View style={styles.itemContainer}>
35
+    <TouchableOpacity
36
+      activeOpacity={0.75}
37
+      style={styles.itemContainer}
38
+      onPress={() => Navigation.push(this, {
39
+        component: {
40
+          name: Screens.CocktailDetailsScreen,
41
+          passProps: { ...item }
42
+        }
43
+      })}>
39
       <Image
44
       <Image
40
         source={item.image}
45
         source={item.image}
41
         style={styles.image}
46
         style={styles.image}
47
           <Text style={styles.ingredients}>{slice(item.ingredients, 0, 3).map(i => i.name).join(' • ')}</Text>
52
           <Text style={styles.ingredients}>{slice(item.ingredients, 0, 3).map(i => i.name).join(' • ')}</Text>
48
         </View>
53
         </View>
49
       </View>
54
       </View>
50
-    </View>
55
+    </TouchableOpacity>
51
   )
56
   )
52
 
57
 
53
   keyExtractor = item => item.id;
58
   keyExtractor = item => item.id;