summary refs log tree commit diff
path: root/App.js
blob: 2de413e86e17b10f51fd2d60e7db6dc0d982d063 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React, { Component } from "react";
import { Animated, TextInput, Text, View, StyleSheet, Button } from "react-native";

const force0 = 100; // px/ms
const g = 10;
const t = 1000;

class App extends Component {
  state = {
    animationProgress: new Animated.Value(0),
    alpha: 70,
  };

  fadeIn = () => {
    //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();
  };

  fadeStop = () => {
    Animated.timing(this.state.animationProgress).stop();
  };


  render() {
    return (
      <View style={styles.container}>

      {/*komponent animacyjny*/}

        <Animated.View
          style={[
            styles.fadingContainer,
            {
              transform:
              [{

                translateY: Animated.subtract(0, Animated.multiply(Animated.subtract(force0 * Math.sin(this.state.alpha * Math.PI / 180), Animated.multiply(g, this.state.animationProgress.interpolate({
                                inputRange: [0, 1],
                                outputRange: [0, 10],
                            }))), this.state.animationProgress.interpolate({
                                inputRange: [0, 1],
                                outputRange: [0, 10],
                            }))),

              },
              {translateX: Animated.multiply(force0 * Math.cos(this.state.alpha * Math.PI / 180), this.state.animationProgress.interpolate({
                                inputRange: [0, 1],
                                outputRange: [0, 10],
                            })),},

            ],
            }
          ]}
        >


        </Animated.View>


        {/*komponent statyczny*/}
        <View style={styles.buttonRow}>
          <Button title="Rzut" onPress={this.fadeIn} />
          <Button title="Stop" onPress={this.fadeStop} />

        </View>
        <View>
          <Text>Be nice, give me int</Text>
          <TextInput onChangeText={value => this.setState({ alpha: Number(value) })} value={this.state.alpha}/>
        </View>
      </View>
    );
  }
}

const styles = StyleSheet.create({
  container: {
    flex: 1,
    alignItems: "center",
    justifyContent: "center",
  },
  fadingContainer: {
    paddingVertical: 8,
    paddingHorizontal: 16,
    backgroundColor: "powderblue",
    opacity: 1,
  },
  fadingText: {
    fontSize: 28,
    textAlign: "center",
    margin: 10
  },
  buttonRow: {
    flexDirection: "row",
    marginVertical: 16
  }
});

export default App;