mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React, {useEffect} from 'react'
2import {observer} from 'mobx-react-lite'
3import {Animated, Easing, Platform, StyleSheet, View} from 'react-native'
4import {ComposePost} from '../com/composer/Composer'
5import {useComposerState} from 'state/shell/composer'
6import {useAnimatedValue} from 'lib/hooks/useAnimatedValue'
7import {usePalette} from 'lib/hooks/usePalette'
8
9export const Composer = observer(function ComposerImpl({
10 winHeight,
11}: {
12 winHeight: number
13}) {
14 const state = useComposerState()
15 const pal = usePalette('default')
16 const initInterp = useAnimatedValue(0)
17
18 useEffect(() => {
19 if (state) {
20 Animated.timing(initInterp, {
21 toValue: 1,
22 duration: 300,
23 easing: Easing.out(Easing.exp),
24 useNativeDriver: true,
25 }).start()
26 } else {
27 initInterp.setValue(0)
28 }
29 }, [initInterp, state])
30 const wrapperAnimStyle = {
31 transform: [
32 {
33 translateY: initInterp.interpolate({
34 inputRange: [0, 1],
35 outputRange: [winHeight, 0],
36 }),
37 },
38 ],
39 }
40
41 // rendering
42 // =
43
44 if (!state) {
45 return <View />
46 }
47
48 return (
49 <Animated.View
50 style={[styles.wrapper, pal.view, wrapperAnimStyle]}
51 aria-modal
52 accessibilityViewIsModal>
53 <ComposePost
54 replyTo={state.replyTo}
55 onPost={state.onPost}
56 quote={state.quote}
57 mention={state.mention}
58 text={state.text}
59 imageUris={state.imageUris}
60 />
61 </Animated.View>
62 )
63})
64
65const styles = StyleSheet.create({
66 wrapper: {
67 position: 'absolute',
68 top: 0,
69 bottom: 0,
70 width: '100%',
71 ...Platform.select({
72 ios: {
73 paddingTop: 24,
74 },
75 }),
76 },
77})