Add back mobile compose input
This commit is contained in:
@@ -1,11 +1,16 @@
|
|||||||
import {useCallback, useMemo, useRef, useState} from 'react'
|
import {useCallback, useMemo, useRef, useState} from 'react'
|
||||||
import {useWindowDimensions, View} from 'react-native'
|
import {useWindowDimensions, View} from 'react-native'
|
||||||
|
import Animated from 'react-native-reanimated'
|
||||||
|
import {useSafeAreaInsets} from 'react-native-safe-area-context'
|
||||||
import {Trans} from '@lingui/macro'
|
import {Trans} from '@lingui/macro'
|
||||||
|
|
||||||
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
|
import {useInitialNumToRender} from '#/lib/hooks/useInitialNumToRender'
|
||||||
|
import {useMinimalShellFabTransform} from '#/lib/hooks/useMinimalShellTransform'
|
||||||
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
import {useOpenComposer} from '#/lib/hooks/useOpenComposer'
|
||||||
|
import {clamp} from '#/lib/numbers'
|
||||||
import {type ThreadViewOption} from '#/state/queries/preferences/useThreadPreferences'
|
import {type ThreadViewOption} from '#/state/queries/preferences/useThreadPreferences'
|
||||||
import {type ThreadItem, usePostThread} from '#/state/queries/usePostThread'
|
import {type ThreadItem, usePostThread} from '#/state/queries/usePostThread'
|
||||||
|
import {useSession} from '#/state/session'
|
||||||
import {type OnPostSuccessData} from '#/state/shell/composer'
|
import {type OnPostSuccessData} from '#/state/shell/composer'
|
||||||
import {PostThreadComposePrompt} from '#/view/com/post-thread/PostThreadComposePrompt'
|
import {PostThreadComposePrompt} from '#/view/com/post-thread/PostThreadComposePrompt'
|
||||||
import {List, type ListMethods} from '#/view/com/util/List'
|
import {List, type ListMethods} from '#/view/com/util/List'
|
||||||
@@ -28,7 +33,7 @@ import {
|
|||||||
ThreadItemTreePost,
|
ThreadItemTreePost,
|
||||||
ThreadItemTreePostSkeleton,
|
ThreadItemTreePostSkeleton,
|
||||||
} from '#/screens/PostThread/components/ThreadItemTreePost'
|
} from '#/screens/PostThread/components/ThreadItemTreePost'
|
||||||
import {native, platform,useBreakpoints, web} from '#/alf'
|
import {atoms as a, native, platform, useBreakpoints, web} from '#/alf'
|
||||||
import * as Layout from '#/components/Layout'
|
import * as Layout from '#/components/Layout'
|
||||||
import {ListFooter} from '#/components/Lists'
|
import {ListFooter} from '#/components/Lists'
|
||||||
|
|
||||||
@@ -36,9 +41,9 @@ const PARENT_CHUNK_SIZE = 5
|
|||||||
const CHILDREN_CHUNK_SIZE = 50
|
const CHILDREN_CHUNK_SIZE = 50
|
||||||
|
|
||||||
export function Inner({uri}: {uri: string | undefined}) {
|
export function Inner({uri}: {uri: string | undefined}) {
|
||||||
const {gtPhone} = useBreakpoints()
|
const {gtMobile} = useBreakpoints()
|
||||||
// const {hasSession, currentAccount} = useSession()
|
const {hasSession} = useSession()
|
||||||
const initialNumToRender = useInitialNumToRender()
|
const initialNumToRender = useInitialNumToRender() // TODO
|
||||||
const {height: windowHeight} = useWindowDimensions()
|
const {height: windowHeight} = useWindowDimensions()
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -79,6 +84,15 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
})
|
})
|
||||||
}, [thread, openComposer, optimisticOnPostReply])
|
}, [thread, openComposer, optimisticOnPostReply])
|
||||||
|
|
||||||
|
const canReply = useMemo(() => {
|
||||||
|
if (thread.state.error) return false
|
||||||
|
for (const item of thread.data.items) {
|
||||||
|
if (item.type === 'threadPost' && item.depth === 0) {
|
||||||
|
return !item.value.post?.viewer?.replyDisabled
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}, [thread.state.error, thread.data.items])
|
||||||
const [maxParentCount, setMaxParentCount] = useState(PARENT_CHUNK_SIZE)
|
const [maxParentCount, setMaxParentCount] = useState(PARENT_CHUNK_SIZE)
|
||||||
const [maxChildrenCount, setMaxChildrenCount] = useState(CHILDREN_CHUNK_SIZE)
|
const [maxChildrenCount, setMaxChildrenCount] = useState(CHILDREN_CHUNK_SIZE)
|
||||||
const totalParentCount = useRef(0) // recomputed below
|
const totalParentCount = useRef(0) // recomputed below
|
||||||
@@ -356,7 +370,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
} else if (item.type === 'replyComposer') {
|
} else if (item.type === 'replyComposer') {
|
||||||
return (
|
return (
|
||||||
<View>
|
<View>
|
||||||
{gtPhone && (
|
{gtMobile && (
|
||||||
<PostThreadComposePrompt onPressCompose={onReplyToAnchor} />
|
<PostThreadComposePrompt onPressCompose={onReplyToAnchor} />
|
||||||
)}
|
)}
|
||||||
</View>
|
</View>
|
||||||
@@ -378,7 +392,7 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
}
|
}
|
||||||
return null
|
return null
|
||||||
},
|
},
|
||||||
[thread, optimisticOnPostReply, onReplyToAnchor, gtPhone],
|
[thread, optimisticOnPostReply, onReplyToAnchor, gtMobile],
|
||||||
)
|
)
|
||||||
|
|
||||||
const prepareForParamsUpdate = useCallback(() => {
|
const prepareForParamsUpdate = useCallback(() => {
|
||||||
@@ -459,8 +473,8 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
ListFooterComponent={
|
ListFooterComponent={
|
||||||
<ListFooter
|
<ListFooter
|
||||||
/*
|
/*
|
||||||
* 200 is based on the minimum height of a post. This is enough
|
* 200 is based on the minimum height of an anchor post. This is
|
||||||
* extra height for the `maintainVisPos` to work without
|
* enough extra height for the `maintainVisPos` to work without
|
||||||
* causing weird jumps on web or glitches on native
|
* causing weird jumps on web or glitches on native
|
||||||
*/
|
*/
|
||||||
height={windowHeight - 200}
|
height={windowHeight - 200}
|
||||||
@@ -472,10 +486,34 @@ export function Inner({uri}: {uri: string | undefined}) {
|
|||||||
sideBorders={false}
|
sideBorders={false}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!gtMobile && canReply && hasSession && (
|
||||||
|
<MobileComposePrompt onPressReply={onReplyToAnchor} />
|
||||||
|
)}
|
||||||
</>
|
</>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function MobileComposePrompt({onPressReply}: {onPressReply: () => unknown}) {
|
||||||
|
const safeAreaInsets = useSafeAreaInsets()
|
||||||
|
const fabMinimalShellTransform = useMinimalShellFabTransform()
|
||||||
|
|
||||||
|
return (
|
||||||
|
<Animated.View
|
||||||
|
style={[
|
||||||
|
a.fixed,
|
||||||
|
fabMinimalShellTransform,
|
||||||
|
{
|
||||||
|
left: 0,
|
||||||
|
right: 0,
|
||||||
|
bottom: clamp(safeAreaInsets.bottom, 13, 60),
|
||||||
|
},
|
||||||
|
]}>
|
||||||
|
<PostThreadComposePrompt onPressCompose={onPressReply} />
|
||||||
|
</Animated.View>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
const keyExtractor = (item: ThreadItem) => {
|
const keyExtractor = (item: ThreadItem) => {
|
||||||
return item.key
|
return item.key
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user