|
1 |
| -import React, { useEffect, useState } from "react"; |
2 |
| -import { StyleSheet, Text, View, SafeAreaView, Dimensions } from "react-native"; |
3 |
| -import { AppLoading } from "expo"; |
4 |
| -// import Card from "./components/Card"; |
5 |
| -import SkeletonComp from "./components/Card"; |
| 1 | +import React, { useRef } from "react"; |
| 2 | +import { StyleSheet, Text, View, Image } from "react-native"; |
| 3 | +import Logo from "./components/Logo"; |
| 4 | +import Animated, { |
| 5 | + useCode, |
| 6 | + cond, |
| 7 | + eq, |
| 8 | + set, |
| 9 | + interpolate, |
| 10 | + SpringUtils, |
| 11 | +} from "react-native-reanimated"; |
| 12 | +import { |
| 13 | + withTimingTransition, |
| 14 | + onGestureEvent, |
| 15 | + withSpringTransition, |
| 16 | +} from "react-native-redash"; |
| 17 | +import { SCREEN_HEIGHT, LOGIN_VIEW_HEIGHT } from "./Constants"; |
| 18 | +import { |
| 19 | + TextInput, |
| 20 | + TapGestureHandler, |
| 21 | + State, |
| 22 | +} from "react-native-gesture-handler"; |
| 23 | +import OverlayBg from "./components/OverlayBg"; |
| 24 | +import HeaderBackArrow from "./components/HeaderBackArrow"; |
| 25 | +import AnimatedPlaceholder from "./components/AnimatedPlaceholder"; |
6 | 26 |
|
7 |
| -const { width } = Dimensions.get("window"); |
8 | 27 | export default function App() {
|
9 |
| - const [isReady, setIsReady] = useState(false); |
| 28 | + const scale = useRef(new Animated.Value(0)); |
| 29 | + const scaleAnimation = withTimingTransition(scale.current); |
10 | 30 |
|
11 |
| - useEffect(() => { |
12 |
| - let timer1 = setTimeout(() => setIsReady(true), 2000); |
13 |
| - return () => { |
14 |
| - clearTimeout(timer1); |
15 |
| - }; |
16 |
| - }, []); |
| 31 | + const innerLoginY = interpolate(scaleAnimation, { |
| 32 | + inputRange: [0, 1], |
| 33 | + outputRange: [LOGIN_VIEW_HEIGHT, 0], |
| 34 | + }); |
| 35 | + |
| 36 | + const gestureState = useRef(new Animated.Value(State.UNDETERMINED)); |
| 37 | + const gestureHandler = onGestureEvent({ state: gestureState.current }); |
| 38 | + |
| 39 | + const backArrowGestureState = useRef(new Animated.Value(State.UNDETERMINED)); |
| 40 | + const backArrowGestureHandler = onGestureEvent({ |
| 41 | + state: backArrowGestureState.current, |
| 42 | + }); |
| 43 | + |
| 44 | + const isOpen = useRef(new Animated.Value(0)); |
| 45 | + const isOpenAnimation = withSpringTransition(isOpen.current, { |
| 46 | + ...SpringUtils.makeDefaultConfig(), |
| 47 | + overshootClamping: true, |
| 48 | + damping: new Animated.Value(20), |
| 49 | + }); |
| 50 | + |
| 51 | + const outerLoginY = interpolate(isOpenAnimation, { |
| 52 | + inputRange: [0, 1], |
| 53 | + outputRange: [SCREEN_HEIGHT - LOGIN_VIEW_HEIGHT, LOGIN_VIEW_HEIGHT / 2], |
| 54 | + }); |
| 55 | + |
| 56 | + const headingOpacity = interpolate(isOpenAnimation, { |
| 57 | + inputRange: [0, 1], |
| 58 | + outputRange: [1, 0], |
| 59 | + }); |
| 60 | + |
| 61 | + useCode(() => |
| 62 | + cond( |
| 63 | + eq(gestureState.current, State.END), |
| 64 | + [cond(eq(isOpen.current, 0), set(isOpen.current, 1))], |
| 65 | + [gestureState.current], |
| 66 | + ), |
| 67 | + ); |
| 68 | + useCode(() => cond(eq(scale.current, 0), set(scale.current, 1)), []); |
| 69 | + |
| 70 | + useCode( |
| 71 | + () => |
| 72 | + cond(eq(backArrowGestureState.current, State.END), [ |
| 73 | + set(gestureState.current, State.UNDETERMINED), |
| 74 | + set(isOpen.current, 0), |
| 75 | + ]), |
| 76 | + [backArrowGestureState.current], |
| 77 | + ); |
17 | 78 |
|
18 | 79 | return (
|
19 | 80 | <View style={styles.container}>
|
20 |
| - <SafeAreaView style={{ backgroundColor: "#5f5f5f" }} /> |
21 |
| - {isReady ? ( |
22 |
| - <View |
23 |
| - style={{ height: 200, width: width, backgroundColor: "grey" }} |
24 |
| - ></View> |
25 |
| - ) : ( |
26 |
| - <SkeletonComp |
27 |
| - height={200} |
28 |
| - width={width} |
29 |
| - style={{ marginVertical: 20 }} |
30 |
| - ></SkeletonComp> |
31 |
| - )} |
| 81 | + <View style={{ ...styles.logoContainer }}> |
| 82 | + <Logo scale={scaleAnimation} /> |
| 83 | + </View> |
| 84 | + <HeaderBackArrow |
| 85 | + isOpenAnimation={isOpenAnimation} |
| 86 | + gestureHandler={{ ...backArrowGestureHandler }} |
| 87 | + /> |
| 88 | + |
| 89 | + <Animated.View |
| 90 | + style={{ |
| 91 | + backgroundColor: "white", |
| 92 | + ...StyleSheet.absoluteFill, |
| 93 | + transform: [{ translateY: outerLoginY }], |
| 94 | + }} |
| 95 | + > |
| 96 | + <OverlayBg isOpenAnimation={isOpenAnimation} /> |
| 97 | + <Animated.View> |
| 98 | + <Animated.View |
| 99 | + style={{ |
| 100 | + height: LOGIN_VIEW_HEIGHT, |
| 101 | + |
| 102 | + backgroundColor: "white", |
| 103 | + |
| 104 | + transform: [{ translateY: innerLoginY }], |
| 105 | + }} |
| 106 | + > |
| 107 | + <Animated.View |
| 108 | + style={{ ...styles.heading, opacity: headingOpacity }} |
| 109 | + > |
| 110 | + <Text style={{ fontSize: 24 }}>Get moving with Uber</Text> |
| 111 | + </Animated.View> |
| 112 | + |
| 113 | + <TapGestureHandler {...gestureHandler}> |
| 114 | + <Animated.View> |
| 115 | + <Animated.View |
| 116 | + pointerEvents="none" |
| 117 | + style={{ ...styles.textInputContainer }} |
| 118 | + > |
| 119 | + <AnimatedPlaceholder isOpenAnimation={isOpenAnimation} /> |
| 120 | + <Image |
| 121 | + source={require("./assets/india.png")} |
| 122 | + style={{ ...styles.image }} |
| 123 | + /> |
| 124 | + <Text style={{ ...styles.prefix }}>+91</Text> |
| 125 | + <TextInput |
| 126 | + keyboardType="number-pad" |
| 127 | + style={{ ...styles.textInput }} |
| 128 | + placeholder="Enter your mobile number" |
| 129 | + /> |
| 130 | + </Animated.View> |
| 131 | + </Animated.View> |
| 132 | + </TapGestureHandler> |
| 133 | + </Animated.View> |
| 134 | + </Animated.View> |
| 135 | + </Animated.View> |
32 | 136 | </View>
|
33 | 137 | );
|
34 | 138 | }
|
35 | 139 |
|
36 | 140 | const styles = StyleSheet.create({
|
37 | 141 | container: {
|
38 | 142 | flex: 1,
|
39 |
| - backgroundColor: "#fff", |
| 143 | + backgroundColor: "#2289d6", |
| 144 | + }, |
| 145 | + logoContainer: { |
| 146 | + flex: 1, |
| 147 | + alignItems: "center", |
| 148 | + justifyContent: "center", |
| 149 | + }, |
| 150 | + heading: { |
| 151 | + alignItems: "flex-start", |
| 152 | + marginHorizontal: 25, |
| 153 | + marginTop: 50, |
| 154 | + }, |
| 155 | + image: { |
| 156 | + height: 24, |
| 157 | + width: 24, |
| 158 | + resizeMode: "contain", |
| 159 | + }, |
| 160 | + prefix: { |
| 161 | + fontSize: 20, |
| 162 | + paddingHorizontal: 10, |
| 163 | + }, |
| 164 | + textInput: { |
| 165 | + flex: 1, |
| 166 | + fontSize: 20, |
| 167 | + }, |
| 168 | + textInputContainer: { |
| 169 | + flexDirection: "row", |
| 170 | + margin: 25, |
40 | 171 | },
|
41 | 172 | });
|
0 commit comments