|
| 1 | +import { LinearGradient } from "expo-linear-gradient"; |
| 2 | +import * as React from "react"; |
| 3 | +import { View, StyleSheet, Text, ImageBackground, TouchableOpacity } from "react-native"; |
| 4 | +import { SharedElement } from "react-navigation-shared-element"; |
| 5 | +import { NavigationStackProp } from "react-navigation-stack"; |
| 6 | + |
| 7 | +import { Icon } from "../components"; |
| 8 | +import { Item } from "../data"; |
| 9 | + |
| 10 | +type Props = { |
| 11 | + navigation: NavigationStackProp<any>; |
| 12 | + item: Item; |
| 13 | + modal: "none" | "full" | "sheet"; |
| 14 | +}; |
| 15 | + |
| 16 | +export const DetailComponentImageBackground = (props: Props) => { |
| 17 | + const { item, navigation, modal = "none" } = props; |
| 18 | + return ( |
| 19 | + <View style={styles.container}> |
| 20 | + <SharedElement id={`${item.id}.image`} style={StyleSheet.absoluteFill}> |
| 21 | + <ImageBackground style={styles.image} resizeMode="cover" source={item.image}> |
| 22 | + <Text style={styles.imageBackgroundTextContent}>Content inside ImageBackground</Text> |
| 23 | + </ImageBackground> |
| 24 | + </SharedElement> |
| 25 | + |
| 26 | + <SharedElement id={`${item.id}.logo`} style={styles.logoContainer}> |
| 27 | + <ImageBackground |
| 28 | + style={styles.logo} |
| 29 | + resizeMode="contain" |
| 30 | + source={require("../../assets/logo.png")} |
| 31 | + /> |
| 32 | + </SharedElement> |
| 33 | + |
| 34 | + <View style={styles.content}> |
| 35 | + <SharedElement |
| 36 | + id={`${item.id}.gradient`} |
| 37 | + style={StyleSheet.absoluteFill} |
| 38 | + > |
| 39 | + <LinearGradient |
| 40 | + colors={["transparent", "rgba(0,0,0,0.9)"]} |
| 41 | + style={StyleSheet.absoluteFill} |
| 42 | + /> |
| 43 | + </SharedElement> |
| 44 | + <SharedElement id={`${item.id}.title`}> |
| 45 | + <Text style={styles.title}>{item.title}</Text> |
| 46 | + </SharedElement> |
| 47 | + |
| 48 | + <SharedElement id={`${item.id}.description`}> |
| 49 | + <Text style={styles.description}>{item.description}</Text> |
| 50 | + </SharedElement> |
| 51 | + </View> |
| 52 | + |
| 53 | + {modal !== "none" ? ( |
| 54 | + <View |
| 55 | + style={[ |
| 56 | + styles.header, |
| 57 | + modal === "sheet" ? styles.sheetHeader : undefined, |
| 58 | + ]} |
| 59 | + > |
| 60 | + <TouchableOpacity |
| 61 | + activeOpacity={0.5} |
| 62 | + onPress={() => navigation.goBack()} |
| 63 | + > |
| 64 | + <SharedElement id="close"> |
| 65 | + <Icon style={styles.icon} name="ios-close" /> |
| 66 | + </SharedElement> |
| 67 | + </TouchableOpacity> |
| 68 | + </View> |
| 69 | + ) : undefined} |
| 70 | + </View> |
| 71 | + ); |
| 72 | +}; |
| 73 | + |
| 74 | +const styles = StyleSheet.create({ |
| 75 | + container: { |
| 76 | + flex: 1, |
| 77 | + alignItems: "center", |
| 78 | + }, |
| 79 | + header: { |
| 80 | + position: "absolute", |
| 81 | + right: 16, |
| 82 | + top: 32, |
| 83 | + }, |
| 84 | + sheetHeader: { |
| 85 | + right: 16, |
| 86 | + top: 16, |
| 87 | + }, |
| 88 | + icon: { |
| 89 | + fontSize: 40, |
| 90 | + color: "white", |
| 91 | + }, |
| 92 | + image: { |
| 93 | + width: "100%", |
| 94 | + height: "100%", |
| 95 | + }, |
| 96 | + logoContainer: { |
| 97 | + position: "absolute", |
| 98 | + left: 4, |
| 99 | + top: 12, |
| 100 | + height: 60, |
| 101 | + width: 160, |
| 102 | + }, |
| 103 | + logo: { |
| 104 | + width: "100%", |
| 105 | + height: "100%", |
| 106 | + }, |
| 107 | + content: { |
| 108 | + position: "absolute", |
| 109 | + left: 0, |
| 110 | + right: 0, |
| 111 | + bottom: 0, |
| 112 | + padding: 20, |
| 113 | + }, |
| 114 | + title: { |
| 115 | + marginTop: 20, |
| 116 | + color: "white", |
| 117 | + fontSize: 60, |
| 118 | + fontWeight: "bold", |
| 119 | + textShadowColor: "black", |
| 120 | + textShadowRadius: 8, |
| 121 | + textShadowOffset: { |
| 122 | + width: 0, |
| 123 | + height: 1, |
| 124 | + }, |
| 125 | + }, |
| 126 | + description: { |
| 127 | + color: "white", |
| 128 | + fontSize: 17, |
| 129 | + fontWeight: "bold", |
| 130 | + textShadowColor: "black", |
| 131 | + textShadowRadius: 4, |
| 132 | + textShadowOffset: { |
| 133 | + width: 0, |
| 134 | + height: 1, |
| 135 | + }, |
| 136 | + }, |
| 137 | + imageBackgroundTextContent: { |
| 138 | + color: "white", |
| 139 | + fontSize: 17, |
| 140 | + fontWeight: "bold", |
| 141 | + textShadowColor: "black", |
| 142 | + textShadowRadius: 4, |
| 143 | + textShadowOffset: { |
| 144 | + width: 0, |
| 145 | + height: 1, |
| 146 | + }, |
| 147 | + alignSelf: 'center', |
| 148 | + marginTop: 'auto', |
| 149 | + marginBottom: 'auto' |
| 150 | + } |
| 151 | +}); |
0 commit comments