Skip to content

Commit

Permalink
video fixes (keybase#25720)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisnojima authored Jun 9, 2023
1 parent e9e3639 commit 0a51fb3
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 100 deletions.
2 changes: 1 addition & 1 deletion shared/chat/conversation/fwd-msg/team-picker.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ const TeamPicker = (props: Props) => {
{
if (message.inlineVideoPlayable) {
const url = `${message.fileURL}&contentforce=true`
preview = url ? <Kb.Video allowFile={true} url={url} /> : null
preview = url ? <Kb.Video allowFile={true} url={url} muted={true} /> : null
} else {
const src = message.fileURL ?? message.previewURL
preview = src ? <Kb.ZoomableImage src={src} style={styles.image} /> : null
Expand Down
98 changes: 1 addition & 97 deletions shared/chat/conversation/list-area/index.native.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import SpecialBottomMessage from '../messages/special-bottom-message'
import SpecialTopMessage from '../messages/special-top-message'
import type * as Types from '../../../constants/types/chat2'
import type {ItemType} from '.'
import {Animated, FlatList} from 'react-native'
import {FlatList} from 'react-native'
import {ConvoIDContext, SeparatorMapContext} from '../messages/ids-context'
import {FlashList, type ListRenderItemInfo} from '@shopify/flash-list'
import {getMessageRender} from '../messages/wrapper'
Expand All @@ -23,97 +23,6 @@ import {usingFlashList} from './flashlist-config'

const List = usingFlashList ? FlashList : FlatList

// Bookkeep whats animating so it finishes and isn't replaced, if we've animated it we keep the key and use null
const animatingMap = new Map<string, null | React.ReactElement>()

type AnimatedChildProps = {
animatingKey: string
children: React.ReactNode
}
const AnimatedChild = React.memo(function AnimatedChild({children, animatingKey}: AnimatedChildProps) {
const translateY = new Animated.Value(999)
const opacity = new Animated.Value(0)
React.useEffect(() => {
// on unmount, mark it null
return () => {
animatingMap.set(animatingKey, null)
}
}, [animatingKey])

// only animate up once
const onceRef = React.useRef(false)

React.useEffect(() => {
onceRef.current = false
}, [animatingKey])

return (
<Animated.View
style={{opacity, overflow: 'hidden', transform: [{translateY}], width: '100%'}}
onLayout={(e: any) => {
const {height} = e.nativeEvent.layout
if (onceRef.current) {
return
}
onceRef.current = true
translateY.setValue(height + 10)
Animated.parallel([
Animated.timing(opacity, {
duration: 200,
toValue: 1,
useNativeDriver: true,
}),
Animated.timing(translateY, {
duration: 200,
toValue: 0,
useNativeDriver: true,
}),
]).start(() => {
animatingMap.set(animatingKey, null)
})
}}
>
{children}
</Animated.View>
)
})

type SentProps = {
children?: React.ReactElement
ordinal: Types.Ordinal
}
const Sent = React.memo(function Sent({ordinal}: SentProps) {
const conversationIDKey = React.useContext(ConvoIDContext)
const {subType, youSent} = Container.useSelector(state => {
const you = state.config.username
const message = state.chat2.messageMap.get(conversationIDKey)?.get(ordinal)
const youSent = message && message.author === you && message.ordinal !== message.id
const subType = message ? Constants.getMessageRenderType(message) : undefined
return {subType, youSent}
}, shallowEqual)
const key = `${conversationIDKey}:${ordinal}`
const state = animatingMap.get(key)

if (!subType) return null

// if its animating always show it
if (state) {
return state
}

const Clazz = getMessageRender(subType)
if (!Clazz) return null
const children = <Clazz ordinal={ordinal} />
// if state is null we already animated it
if (youSent && state === undefined) {
const c = <AnimatedChild animatingKey={key}>{children}</AnimatedChild>
animatingMap.set(key, c)
return c
} else {
return children || null
}
})

// We load the first thread automatically so in order to mark it read
// we send an action on the first mount once
let markedInitiallyLoaded = false
Expand Down Expand Up @@ -238,11 +147,6 @@ const ConversationList = React.memo(function ConversationList(p: {
if (!ordinal) {
return null
}

if (!index) {
return <Sent ordinal={ordinal} />
}

const type = messageTypeMap?.get(ordinal) ?? 'text'
if (!type) return null
const Clazz = getMessageRender(type)
Expand Down
83 changes: 83 additions & 0 deletions shared/chat/conversation/messages/wrapper/sent.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
import * as React from 'react'
import {Animated} from 'react-native'
// Bookkeep whats animating so it finishes and isn't replaced, if we've animated it we keep the key and use null
const animatingMap = new Map<string, null | React.ReactElement>()

type AnimatedChildProps = {
animatingKey: string
children: React.ReactNode
}
const AnimatedChild = React.memo(function AnimatedChild({children, animatingKey}: AnimatedChildProps) {
const [done, setDone] = React.useState(false)
const translateY = React.useRef(new Animated.Value(999)).current
const opacity = React.useRef(new Animated.Value(0)).current
React.useEffect(() => {
// on unmount, mark it null
return () => {
animatingMap.set(animatingKey, null)
}
}, [animatingKey])

// only animate up once
const onceRef = React.useRef(false)

React.useEffect(() => {
onceRef.current = false
}, [animatingKey])

return done ? (
<>{children}</>
) : (
<Animated.View
style={{opacity, overflow: 'hidden', transform: [{translateY}], width: '100%'}}
onLayout={(e: any) => {
if (onceRef.current) {
return
}
const {height} = e.nativeEvent.layout
onceRef.current = true
translateY.setValue(height + 10)
Animated.parallel([
Animated.timing(opacity, {
duration: 200,
toValue: 1,
useNativeDriver: true,
}),
Animated.timing(translateY, {
duration: 200,
toValue: 0,
useNativeDriver: true,
}),
]).start(() => {
animatingMap.set(animatingKey, null)
setDone(true)
})
}}
>
{children}
</Animated.View>
)
})

type SentProps = {
children: React.ReactNode
sentKey: string
}
export const Sent = function Sent(p: SentProps) {
const {children, sentKey} = p
const state = animatingMap.get(sentKey)

// if its animating always show it
if (state) {
return state
}

// if state is null we already animated it
if (state === undefined) {
const c = <AnimatedChild animatingKey={sentKey}>{children}</AnimatedChild>
animatingMap.set(sentKey, c)
return c
} else {
return <>{children}</>
}
}
14 changes: 12 additions & 2 deletions shared/chat/conversation/messages/wrapper/wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import SendIndicator from './send-indicator'
import type * as Types from '../../../../constants/types/chat2'
import capitalize from 'lodash/capitalize'
import {useEdited} from './edited'
import {Sent} from './sent'
// import {useDebugLayout} from '../../../../util/debug'

export type Props = {
Expand Down Expand Up @@ -128,6 +129,7 @@ const useRedux = (conversationIDKey: Types.ConversationIDKey, ordinal: Types.Ord
const you = state.config.username
const m = Constants.getMessage(state, conversationIDKey, ordinal) ?? missingMessage
const {exploded, submitState, author, id, botUsername} = m
const youSent = m.author === you && m.ordinal !== m.id
const exploding = !!m.exploding
const isPendingPayment = Constants.isPendingPaymentMessage(state, m)
const decorate = !exploded && !m.errorReason
Expand Down Expand Up @@ -159,6 +161,7 @@ const useRedux = (conversationIDKey: Types.ConversationIDKey, ordinal: Types.Ord
showSendIndicator,
type,
you,
youSent,
}
}, shallowEqual)
}
Expand Down Expand Up @@ -483,14 +486,21 @@ export const WrapperMessage = React.memo(function WrapperMessage(p: WMProps) {

const {isPendingPayment, decorate, type, hasReactions, isEditing} = mdata
const {ecrType, showSendIndicator, showRevoked, showExplodingCountdown, exploding} = mdata
const {reactionsPopupPosition, showCoinsIcon, botname, you} = mdata
const {reactionsPopupPosition, showCoinsIcon, botname, you, youSent} = mdata

const canFixOverdraw = !isPendingPayment && !showCenteredHighlight && !isEditing

const maybeSentChildren =
Container.isMobile && youSent ? (
<Sent sentKey={`${conversationIDKey}:${ordinal}`}>{children}</Sent>
) : (
children
)

const tsprops = {
botname,
bottomChildren,
children,
children: maybeSentChildren,
decorate,
ecrType,
exploding,
Expand Down

0 comments on commit 0a51fb3

Please sign in to comment.