2021-05-26 17:24:54 +00:00
|
|
|
import React, { useCallback, useState } from 'react';
|
2021-09-13 20:41:05 +00:00
|
|
|
import { StyleSheet, View } from 'react-native';
|
|
|
|
import Animated, { call, cond, greaterOrEq, useCode } from 'react-native-reanimated';
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
import { themes } from '../../../constants/colors';
|
|
|
|
import { CustomIcon } from '../../../lib/Icons';
|
|
|
|
import { useTheme } from '../../../theme';
|
|
|
|
import Touch from '../../../utils/touch';
|
|
|
|
import { hasNotch } from '../../../utils/deviceInfo';
|
|
|
|
|
|
|
|
const SCROLL_LIMIT = 200;
|
|
|
|
const SEND_TO_CHANNEL_HEIGHT = 40;
|
|
|
|
|
|
|
|
const styles = StyleSheet.create({
|
|
|
|
container: {
|
|
|
|
position: 'absolute',
|
|
|
|
right: 15
|
|
|
|
},
|
|
|
|
button: {
|
|
|
|
borderRadius: 25
|
|
|
|
},
|
|
|
|
content: {
|
|
|
|
width: 50,
|
|
|
|
height: 50,
|
|
|
|
borderRadius: 25,
|
|
|
|
borderWidth: 1,
|
|
|
|
alignItems: 'center',
|
|
|
|
justifyContent: 'center'
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2021-12-02 22:11:16 +00:00
|
|
|
interface IRoomNavBottomFAB {
|
|
|
|
y: number;
|
|
|
|
onPress: Function;
|
|
|
|
isThread: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
const NavBottomFAB = ({ y, onPress, isThread }: IRoomNavBottomFAB) => {
|
2021-05-26 17:24:54 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
const [show, setShow] = useState(false);
|
2021-12-02 22:11:16 +00:00
|
|
|
const handleOnPress = useCallback(() => onPress(), []); // TODO - check this
|
|
|
|
const toggle = (v: boolean) => setShow(v);
|
2021-05-26 17:24:54 +00:00
|
|
|
|
2021-09-13 20:41:05 +00:00
|
|
|
useCode(
|
|
|
|
() =>
|
|
|
|
cond(
|
|
|
|
greaterOrEq(y, SCROLL_LIMIT),
|
|
|
|
call([y], () => toggle(true)),
|
|
|
|
call([y], () => toggle(false))
|
|
|
|
),
|
|
|
|
[y]
|
|
|
|
);
|
2021-05-26 17:24:54 +00:00
|
|
|
|
|
|
|
if (!show) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
let bottom = hasNotch ? 100 : 60;
|
|
|
|
if (isThread) {
|
|
|
|
bottom += SEND_TO_CHANNEL_HEIGHT;
|
|
|
|
}
|
|
|
|
return (
|
2021-06-22 19:41:55 +00:00
|
|
|
<Animated.View style={[styles.container, { bottom }]} testID='nav-jump-to-bottom'>
|
2021-09-13 20:41:05 +00:00
|
|
|
<Touch onPress={handleOnPress} theme={theme} style={[styles.button, { backgroundColor: themes[theme].backgroundColor }]}>
|
2021-05-26 17:24:54 +00:00
|
|
|
<View style={[styles.content, { borderColor: themes[theme].borderColor }]}>
|
|
|
|
<CustomIcon name='chevron-down' color={themes[theme].auxiliaryTintColor} size={36} />
|
|
|
|
</View>
|
|
|
|
</Touch>
|
|
|
|
</Animated.View>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default NavBottomFAB;
|