Просмотр исходного кода

Add CocktailDetails screen to playground app

Will be used for shared element transition showcase
Guy Carmeli 5 лет назад
Родитель
Сommit
0b9550f8cc

+ 6
- 0
playground/src/assets/cocktails.js Просмотреть файл

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

+ 1
- 0
playground/src/screens/Screens.js Просмотреть файл

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

+ 1
- 0
playground/src/screens/index.js Просмотреть файл

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

+ 46
- 0
playground/src/screens/sharedElementTransition/CocktailDetailsScreen.js Просмотреть файл

@@ -0,0 +1,46 @@
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 Просмотреть файл

@@ -1,8 +1,9 @@
1 1
 const React = require('react');
2 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 5
 const { slice } = require('lodash');
6
+const Screens = require('../Screens')
6 7
 const data = require('../../assets/cocktails').default;
7 8
 
8 9
 class CocktailsList extends Component {
@@ -16,10 +17,6 @@ class CocktailsList extends Component {
16 17
     }
17 18
   }
18 19
 
19
-  constructor(props) {
20
-    super(props);
21
-  }
22
-
23 20
   render() {
24 21
     return (
25 22
       <FlatList
@@ -35,7 +32,15 @@ class CocktailsList extends Component {
35 32
   separatorComponent = () => <View style={styles.separator} />;
36 33
 
37 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 44
       <Image
40 45
         source={item.image}
41 46
         style={styles.image}
@@ -47,7 +52,7 @@ class CocktailsList extends Component {
47 52
           <Text style={styles.ingredients}>{slice(item.ingredients, 0, 3).map(i => i.name).join(' • ')}</Text>
48 53
         </View>
49 54
       </View>
50
-    </View>
55
+    </TouchableOpacity>
51 56
   )
52 57
 
53 58
   keyExtractor = item => item.id;