This repository has been archived by the owner on Sep 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SVGHeader.js
89 lines (80 loc) · 2.36 KB
/
SVGHeader.js
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
import React, {Component} from 'react';
import {View, StyleSheet} from 'react-native'
import Animated from 'react-native-reanimated'
import Svg, {Path} from "react-native-svg"
import { interpolatePath } from "d3-interpolate-path";
import {deviceWidth} from "./styleHelper"
const {
Value, event, call, block,
} = Animated;
const terrible = `M0,0,L0,80A5900,5900,0,0,0,${deviceWidth},80,L${deviceWidth},0,Z`;
const great = `M0,0,L0,70A600,600,0,0,0,${deviceWidth},70,L${deviceWidth},0,Z`;
const interpolator = interpolatePath(terrible, great);
class SVGHeader extends Component {
y = new Value(0)
onScroll = event(
[
{
nativeEvent: {
contentOffset: {y: this.y},
},
},
]
)
path = React.createRef()
interpolatePath = ([progress]: [number]) => {
const d = interpolator(progress);
console.log('interpolatePath', {d, progress})
if (this.path.current) {
this.path.current.setNativeProps({d});
}
};
render() {
const progress = this.y.interpolate({
inputRange: [0, 600],
outputRange: [1, 0],
extrapolate: 'clamp',
})
return (
<View style={{flex:1}}>
<Animated.View
style={{
height: 60, backgroundColor: 'green',
opacity: progress
}}
>
</Animated.View>
<Svg
style={{marginLeft: -StyleSheet.hairlineWidth, backgroundColor:'grey'}}
viewBox={`0 0 ${deviceWidth} 120`}
width={deviceWidth + StyleSheet.hairlineWidth + StyleSheet.hairlineWidth}
height={120}
>
<Animated.Code>
{
() => block([
call([progress], this.interpolatePath),
])
}
</Animated.Code>
<Path
ref={this.path}
d={great}
fill={'blue'}
stroke={"none"}
/>
</Svg>
<Animated.ScrollView
style={[StyleSheet.absoluteFill, {zIndex: -5}]}
showsVerticalScrollIndicator={true}
scrollEventThrottle={1}
bounces={false}
contentContainerStyle={{height: 1600}}
onScroll={this.onScroll}
/>
</View>
);
}
}
SVGHeader.propTypes = {};
export default SVGHeader;