Add enter/exit animations to modals on web (#2042)

* add reanimated layout animations to modals

* reorder imports

* pass context to scroll handler patches
This commit is contained in:
Samuel Newman 2023-12-01 00:02:46 +00:00 committed by GitHub
parent abe61b7517
commit 9375532698
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 23 deletions

View file

@ -11,31 +11,31 @@ export const useAnimatedScrollHandler: typeof useAnimatedScrollHandler_BUGGY = (
})
return useAnimatedScrollHandler_BUGGY(
{
onBeginDrag(e) {
onBeginDrag(e, ctx) {
if (typeof ref.current !== 'function' && ref.current.onBeginDrag) {
ref.current.onBeginDrag(e)
ref.current.onBeginDrag(e, ctx)
}
},
onEndDrag(e) {
onEndDrag(e, ctx) {
if (typeof ref.current !== 'function' && ref.current.onEndDrag) {
ref.current.onEndDrag(e)
ref.current.onEndDrag(e, ctx)
}
},
onMomentumBegin(e) {
onMomentumBegin(e, ctx) {
if (typeof ref.current !== 'function' && ref.current.onMomentumBegin) {
ref.current.onMomentumBegin(e)
ref.current.onMomentumBegin(e, ctx)
}
},
onMomentumEnd(e) {
onMomentumEnd(e, ctx) {
if (typeof ref.current !== 'function' && ref.current.onMomentumEnd) {
ref.current.onMomentumEnd(e)
ref.current.onMomentumEnd(e, ctx)
}
},
onScroll(e) {
onScroll(e, ctx) {
if (typeof ref.current === 'function') {
ref.current(e)
ref.current(e, ctx)
} else if (ref.current.onScroll) {
ref.current.onScroll(e)
ref.current.onScroll(e, ctx)
}
},
},

View file

@ -1,10 +1,11 @@
import React from 'react'
import {TouchableWithoutFeedback, StyleSheet, View} from 'react-native'
import Animated, {FadeIn, FadeOut} from 'react-native-reanimated'
import {usePalette} from 'lib/hooks/usePalette'
import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries'
import type {Modal as ModalIface} from '#/state/modals'
import {useModals, useModalControls} from '#/state/modals'
import type {Modal as ModalIface} from '#/state/modals'
import * as ConfirmModal from './Confirm'
import * as EditProfileModal from './EditProfile'
import * as ProfilePreviewModal from './ProfilePreview'
@ -129,7 +130,10 @@ function Modal({modal}: {modal: ModalIface}) {
return (
// eslint-disable-next-line react-native-a11y/has-valid-accessibility-descriptors
<TouchableWithoutFeedback onPress={onPressMask}>
<View style={styles.mask}>
<Animated.View
style={styles.mask}
entering={FadeIn.duration(150)}
exiting={FadeOut}>
{/* eslint-disable-next-line react-native-a11y/has-valid-accessibility-descriptors */}
<TouchableWithoutFeedback onPress={onInnerPress}>
<View
@ -142,7 +146,7 @@ function Modal({modal}: {modal: ModalIface}) {
{element}
</View>
</TouchableWithoutFeedback>
</View>
</Animated.View>
</TouchableWithoutFeedback>
)
}

View file

@ -1,5 +1,6 @@
import React from 'react'
import {StyleSheet, View} from 'react-native'
import Animated, {FadeIn, FadeInDown, FadeOut} from 'react-native-reanimated'
import {ComposePost} from '../com/composer/Composer'
import {useComposerState} from 'state/shell/composer'
import {usePalette} from 'lib/hooks/usePalette'
@ -20,8 +21,15 @@ export function Composer({}: {winHeight: number}) {
}
return (
<View style={styles.mask} aria-modal accessibilityViewIsModal>
<View
<Animated.View
style={styles.mask}
aria-modal
accessibilityViewIsModal
entering={FadeIn.duration(150)}
exiting={FadeOut}>
<Animated.View
entering={FadeInDown.duration(200)}
exiting={FadeOut}
style={[
styles.container,
isMobile && styles.containerMobile,
@ -34,8 +42,8 @@ export function Composer({}: {winHeight: number}) {
onPost={state.onPost}
mention={state.mention}
/>
</View>
</View>
</Animated.View>
</Animated.View>
)
}