From 8be0b97fdc90c6cb8f668499d20fb59fb5e9d4d2 Mon Sep 17 00:00:00 2001 From: Miklos Fazekas Date: Tue, 3 Mar 2020 10:37:16 +0100 Subject: [PATCH] Clean up extra animated line points after animation executed --- example/src/examples/AnimatedLine.js | 130 ++++++++++++++++++ example/src/scenes/Home.js | 2 + .../utils/animated/AnimatedLineString.js | 90 +++++++----- 3 files changed, 191 insertions(+), 31 deletions(-) create mode 100755 example/src/examples/AnimatedLine.js diff --git a/example/src/examples/AnimatedLine.js b/example/src/examples/AnimatedLine.js new file mode 100755 index 0000000000..e72d178a01 --- /dev/null +++ b/example/src/examples/AnimatedLine.js @@ -0,0 +1,130 @@ +import React from 'react'; +import {StyleSheet, Easing, Button} from 'react-native'; +import MapboxGL from '@react-native-mapbox-gl/maps'; + +import sheet from '../styles/sheet'; + +import BaseExamplePropTypes from './common/BaseExamplePropTypes'; +import Page from './common/Page'; +import Bubble from './common/Bubble'; + +const lon = -73.99255; +const lat = 40.73581; +const delta = 0.001; + +class AnimatedLine extends React.Component { + static propTypes = { + ...BaseExamplePropTypes, + }; + + constructor(props) { + super(props); + + this.state = { + backgroundColor: 'blue', + coordinates: [[-73.99155, 40.73581]], + + shape: new MapboxGL.AnimatedLineString({ + coordinates: [[lon + delta, lat], [lon, lat], [lon, lat + delta]], // [[lon, lat], [lon + delta, lat + delta]], /// + }), + }; + } + + startAnimate2() { + setTimeout(() => { + this.state.shape + .timing({ + coordinates: [[lon, lat], [lon, lat + delta]], + duration: 1000, + easing: Easing.linear, + }) + .start(); + }, 2000); + setTimeout(() => { + this.state.shape + .timing({ + coordinates: [ + [lon + delta, lat + delta], + [lon + delta, lat + delta + delta], + ], + duration: 1000, + easing: Easing.linear, + }) + .start(); + }, 4000); + } + + startAnimate3() { + const time = 3000; + + setTimeout(() => { + this.state.shape + .timing({ + coordinates: [[lon + delta, lat], [lon, lat], [lon, lat + delta]], + duration: time, + easing: Easing.linear, + }) + .start(); + }, 2000); + + setTimeout(() => { + this.state.shape + .timing({ + coordinates: [ + [lon + delta, lat], + [lon, lat], + [lon + delta, lat + delta], + ], + duration: time, + easing: Easing.linear, + }) + .start(); + }, 4000); + + setTimeout(() => { + this.state.shape + .timing({ + coordinates: [[lon, lat], [lon, lat + delta]], + duration: time, + easing: Easing.linear, + }) + .start(); + }, 6000); + } + + render() { + return ( + + (this._map = c)} + onPress={this.onPress} + onDidFinishLoadingMap={this.onDidFinishLoadingMap} + style={sheet.matchParent}> + + + + + + + + +