* Working overlay, WIP

* Ok working with no overlay and global gesture handler

* Ok pretty good on native

* Cleanup

* Cleanup

* add animation

* add transform origin to animation

* Some a11y

* Improve colors

* Explicitly wrap gesture handler

* Add easier abstraction

* Web

* Fix animation

* Cleanup and remove provider

* Include demo for now

* Ok diff interface to avoid collapsed views

* Use dimensions hook

* Adjust overlap, clarify intent of consts

* Revert testing edits

---------

Co-authored-by: Samuel Newman <mozzius@protonmail.com>
This commit is contained in:
Eric Bailey
2025-06-24 22:03:23 -05:00
committed by GitHub
parent cd820709b6
commit 4c1515169a
10 changed files with 693 additions and 5 deletions
+83
View File
@@ -0,0 +1,83 @@
import {createContext, useContext, useMemo, useRef, useState} from 'react'
import {View} from 'react-native'
import {
Gesture,
GestureDetector,
type GestureStateChangeEvent,
type GestureUpdateEvent,
type PanGestureHandlerEventPayload,
} from 'react-native-gesture-handler'
import EventEmitter from 'eventemitter3'
export type GlobalGestureEvents = {
begin: GestureStateChangeEvent<PanGestureHandlerEventPayload>
update: GestureUpdateEvent<PanGestureHandlerEventPayload>
end: GestureStateChangeEvent<PanGestureHandlerEventPayload>
finalize: GestureStateChangeEvent<PanGestureHandlerEventPayload>
}
const Context = createContext<{
events: EventEmitter<GlobalGestureEvents>
register: () => void
unregister: () => void
}>({
events: new EventEmitter<GlobalGestureEvents>(),
register: () => {},
unregister: () => {},
})
export function GlobalGestureEventsProvider({
children,
}: {
children: React.ReactNode
}) {
const refCount = useRef(0)
const events = useMemo(() => new EventEmitter<GlobalGestureEvents>(), [])
const [enabled, setEnabled] = useState(false)
const ctx = useMemo(
() => ({
events,
register() {
refCount.current += 1
if (refCount.current === 1) {
setEnabled(true)
}
},
unregister() {
refCount.current -= 1
if (refCount.current === 0) {
setEnabled(false)
}
},
}),
[events, setEnabled],
)
const gesture = Gesture.Pan()
.runOnJS(true)
.enabled(enabled)
.simultaneousWithExternalGesture()
.onBegin(e => {
events.emit('begin', e)
})
.onUpdate(e => {
events.emit('update', e)
})
.onEnd(e => {
events.emit('end', e)
})
.onFinalize(e => {
events.emit('finalize', e)
})
return (
<Context.Provider value={ctx}>
<GestureDetector gesture={gesture}>
<View collapsable={false}>{children}</View>
</GestureDetector>
</Context.Provider>
)
}
export function useGlobalGestureEvents() {
return useContext(Context)
}
@@ -0,0 +1,9 @@
export function GlobalGestureEventsProvider(_props: {
children: React.ReactNode
}) {
throw new Error('GlobalGestureEventsProvider is not supported on web.')
}
export function useGlobalGestureEvents() {
throw new Error('useGlobalGestureEvents is not supported on web.')
}