From 5a475cbdd01b50e16632cc34e0557df94a7f84f4 Mon Sep 17 00:00:00 2001 From: Patryk Niedźwiedziński Date: Tue, 9 Feb 2021 18:39:53 +0100 Subject: animationProgress -> obliczanie pozycji MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Pozycja obliczana jest za pomocą "procentu" postępu animacji. Dla 0 będzie pozycja początkowa, a dla 1 pozycja końcowa. --- App.js | 105 ++++++++++++++++++++++++++++------------------------------------- 1 file changed, 45 insertions(+), 60 deletions(-) diff --git a/App.js b/App.js index 06d204f..2de413e 100644 --- a/App.js +++ b/App.js @@ -1,61 +1,39 @@ import React, { Component } from "react"; -import { Animated, Text, View, StyleSheet, Button } from "react-native"; +import { Animated, TextInput, Text, View, StyleSheet, Button } from "react-native"; -const force0 = 10; // px/ms -const alpha = 89 * (Math.PI / 180); -const g = .1; -const t = 2000; +const force0 = 100; // px/ms +const g = 10; +const t = 1000; class App extends Component { - // fadeAnim will be used as the value for opacity. Initial Value: 0 state = { - yAnim: new Animated.Value(0), - xAnim: new Animated.Value(0), - v: new Animated.Value(force0 * Math.sin(alpha)) + animationProgress: new Animated.Value(0), + alpha: 70, }; fadeIn = () => { - // move in x-axis - const vx = force0 * Math.cos(alpha); - Animated.timing(this.state.xAnim, { - toValue: vx * t, - duration: t, - useNativeDriver:true, - }).start(); - - // move in y-axis - Animated.timing(this.state.v, { - toValue: force0 * Math.sin(alpha) - g/2*t, - duration: t, - useNativeDriver: true, - }).start(); - Animated.timing(this.state.yAnim, { - toValue: Animated.multiply(this.state.v, t), - duration: t, - useNativeDriver: true, - }).start(); + //start animation + Animated.sequence([ + Animated.timing(this.state.animationProgress, { + toValue: 1, + duration: t, + useNativeDriver: true + }), + Animated.timing(this.state.animationProgress, { + toValue: 1, + duration: 250, + useNativeDriver: true + }), + Animated.timing(this.state.animationProgress, { + toValue: 0, + duration: 500, + useNativeDriver: true + }), + ]).start(); }; - //funkcja ustawiajÄ…ca zmianÄ™ wartoÅ›ci stanu fadeAnim z bieżącej na 0 w ciÄ…gu 5s i startujÄ…ca tÄ… zmianÄ™ - fadeOut = () => { - // Will change fadeAnim value to 0 in 5 seconds - Animated.timing(this.state.xAnim, { - toValue: -150, - duration: t, - useNativeDriver:true, - }).start(); - Animated.timing(this.state.yAnim, { - toValue: 0, - duration: t, - useNativeDriver:true, - }).start(); - Animated.timing(this.state.v, { toValue: force0 * Math.sin(alpha), duration: t }) - }; - - //funkcja ustawiajÄ…ca zmianÄ™ wartoÅ›ci stanu fadeAnim z bieżącej na 0 w ciÄ…gu 5s i startujÄ…ca tÄ… zmianÄ™ fadeStop = () => { - Animated.timing(this.state.xAnim).stop(); - Animated.timing(this.state.yAnim).stop(); + Animated.timing(this.state.animationProgress).stop(); }; @@ -64,6 +42,7 @@ class App extends Component { {/*komponent animacyjny*/} + + {/*komponent statyczny*/} -