-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathScrollView.js
49 lines (45 loc) · 1.23 KB
/
ScrollView.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
import { useNavigation } from "@react-navigation/native";
import * as React from "react";
import { useState, useEffect } from "react";
import {
ScrollView as DefaultScrollView,
} from "react-native";
import { useTheme } from "react-native-paper";
export default function ScrollView(props) {
const { onScroll, ...otherProps } = props;
const colors = useTheme().colors;
const [onTop, setOnTop] = useState(true);
const navigation = useNavigation();
function changeHeaderColor(position) {
navigation.setOptions({
headerStyle: {
backgroundColor: position == 0 ?
colors.headerInactive :
colors.headerActive,
},
headerShadowVisible: false,
headerTintColor: position == 0 ?
colors.onHeaderInactive :
colors.onHeader,
});
if (position > 0 && onTop) {
setOnTop(false);
} else if (position == 0 && !onTop) {
setOnTop(true);
}
}
useEffect(() => {
changeHeaderColor(onTop ? 0 : 10);
}, [colors]);
return (
<DefaultScrollView
overScrollMode="never"
onScroll={(e) => {
changeHeaderColor(e.nativeEvent.contentOffset.y);
onScroll?.(e);
}}
scrollEventThrottle={16}
{...otherProps}
/>
);
}