mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Cleanup

Eric Bailey 2b23499a 996e550c

+130 -102
+3 -3
src/App.native.tsx
··· 33 33 ensureGeolocationResolved, 34 34 Provider as GeolocationProvider, 35 35 } from '#/state/geolocation' 36 + import {GlobalGestureEventsProvider} from '#/state/global-gesture-events' 36 37 import {Provider as HomeBadgeProvider} from '#/state/home-badge' 37 38 import {Provider as InvitesStateProvider} from '#/state/invites' 38 39 import {Provider as LightboxStateProvider} from '#/state/lightbox' ··· 73 74 import {BottomSheetProvider} from '../modules/bottom-sheet' 74 75 import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider' 75 76 import {Provider as HideBottomBarBorderProvider} from './lib/hooks/useHideBottomBarBorder' 76 - import {GlobalGestureEvents} from '#/state/shell/GlobalGestureEvents' 77 77 78 78 SplashScreen.preventAutoHideAsync() 79 79 if (isIOS) { ··· 155 155 <HideBottomBarBorderProvider> 156 156 <GestureHandlerRootView 157 157 style={s.h100pct}> 158 - <GlobalGestureEvents> 158 + <GlobalGestureEventsProvider> 159 159 <IntentDialogProvider> 160 160 <TestCtrls /> 161 161 <Shell /> 162 162 <NuxDialogs /> 163 163 </IntentDialogProvider> 164 - </GlobalGestureEvents> 164 + </GlobalGestureEventsProvider> 165 165 </GestureHandlerRootView> 166 166 </HideBottomBarBorderProvider> 167 167 </ServiceAccountManager>
+13 -13
src/components/Tooltip/index.tsx
··· 1 1 import { 2 + createContext, 2 3 useCallback, 4 + useContext, 3 5 useMemo, 4 6 useRef, 5 - createContext, 6 - useContext, 7 7 useState, 8 8 } from 'react' 9 - import {View, Dimensions} from 'react-native' 10 - import {useSafeAreaInsets} from 'react-native-safe-area-context' 9 + import {Dimensions, View} from 'react-native' 11 10 12 - import {Portal} from '#/components/Portal' 13 11 import {atoms as a, useTheme} from '#/alf' 14 - import {useOnInteract} from '#/state/shell/GlobalGestureEvents' 12 + import {useOnGesture} from '#/components/hooks/useOnGesture' 13 + // import {useSafeAreaInsets} from 'react-native-safe-area-context' 14 + import {Portal} from '#/components/Portal' 15 15 import {TIP_SIZE} from '#/components/Tooltip/const' 16 16 17 17 type TooltipContextType = { ··· 160 160 > 161 161 }) { 162 162 const t = useTheme() 163 - const insets = useSafeAreaInsets() 163 + // const insets = useSafeAreaInsets() 164 164 const [bubbleMeasurements, setBubbleMeasurements] = useState< 165 165 | { 166 166 width: number ··· 180 180 } 181 181 182 182 const win = Dimensions.get('window') 183 - const {width: ww, height: wh} = win 184 - const maxTop = insets.top 185 - const maxBottom = wh - insets.bottom 183 + const {width: ww, height: _wh} = win 184 + // const maxTop = insets.top 185 + // const maxBottom = wh - insets.bottom 186 186 const {width: cw, height: ch} = bubbleMeasurements 187 187 const minLeft = a.px_xl.paddingLeft 188 188 const maxLeft = ww - minLeft ··· 211 211 tipTop, 212 212 tipLeft, 213 213 } 214 - }, [targetMeasurements, bubbleMeasurements, insets]) 214 + }, [targetMeasurements, bubbleMeasurements]) 215 215 216 216 const requestCloseWrapped = useCallback(() => { 217 217 setBubbleMeasurements(undefined) 218 218 requestClose() 219 219 }, [requestClose]) 220 220 221 - useOnInteract( 221 + useOnGesture( 222 222 useCallback( 223 223 e => { 224 224 const {x, y} = e ··· 243 243 a.align_start, 244 244 { 245 245 width: 200, 246 - opacity: !!bubbleMeasurements ? 1 : 0, 246 + opacity: bubbleMeasurements ? 1 : 0, 247 247 top: coords.top, 248 248 left: coords.left, 249 249 },
+24
src/components/hooks/useOnGesture/index.ts
··· 1 + import {useEffect} from 'react' 2 + 3 + import { 4 + type GlobalGestureEvents, 5 + useGlobalGestureEvents, 6 + } from '#/state/global-gesture-events' 7 + 8 + /** 9 + * Listen for global gesture events. Callback should be wrapped with 10 + * `useCallback` or otherwise memoized to avoid unnecessary re-renders. 11 + */ 12 + export function useOnGesture( 13 + onGestureCallback: (e: GlobalGestureEvents['begin']) => void, 14 + ) { 15 + const ctx = useGlobalGestureEvents() 16 + useEffect(() => { 17 + ctx.register() 18 + ctx.events.on('begin', onGestureCallback) 19 + return () => { 20 + ctx.unregister() 21 + ctx.events.off('begin', onGestureCallback) 22 + } 23 + }, [ctx, onGestureCallback]) 24 + }
+1
src/components/hooks/useOnGesture/index.web.ts
··· 1 + export function useOnGesture() {}
+80
src/state/global-gesture-events/index.tsx
··· 1 + import {createContext, useContext, useMemo, useRef, useState} from 'react' 2 + import { 3 + Gesture, 4 + GestureDetector, 5 + type GestureStateChangeEvent, 6 + type GestureUpdateEvent, 7 + type PanGestureHandlerEventPayload, 8 + } from 'react-native-gesture-handler' 9 + import EventEmitter from 'eventemitter3' 10 + 11 + export type GlobalGestureEvents = { 12 + begin: GestureStateChangeEvent<PanGestureHandlerEventPayload> 13 + update: GestureUpdateEvent<PanGestureHandlerEventPayload> 14 + end: GestureStateChangeEvent<PanGestureHandlerEventPayload> 15 + finalize: GestureStateChangeEvent<PanGestureHandlerEventPayload> 16 + } 17 + 18 + const Context = createContext<{ 19 + events: EventEmitter<GlobalGestureEvents> 20 + register: () => void 21 + unregister: () => void 22 + }>({ 23 + events: new EventEmitter<GlobalGestureEvents>(), 24 + register: () => {}, 25 + unregister: () => {}, 26 + }) 27 + 28 + export function GlobalGestureEventsProvider({ 29 + children, 30 + }: { 31 + children: React.ReactNode 32 + }) { 33 + const refCount = useRef(0) 34 + const events = useMemo(() => new EventEmitter<GlobalGestureEvents>(), []) 35 + const [enabled, setEnabled] = useState(false) 36 + const ctx = useMemo( 37 + () => ({ 38 + events, 39 + register() { 40 + refCount.current += 1 41 + if (refCount.current === 1) { 42 + setEnabled(true) 43 + } 44 + }, 45 + unregister() { 46 + refCount.current -= 1 47 + if (refCount.current === 0) { 48 + setEnabled(false) 49 + } 50 + }, 51 + }), 52 + [events, setEnabled], 53 + ) 54 + const gesture = Gesture.Pan() 55 + .runOnJS(true) 56 + .enabled(enabled) 57 + .simultaneousWithExternalGesture() 58 + .onBegin(e => { 59 + events.emit('begin', e) 60 + }) 61 + .onUpdate(e => { 62 + events.emit('update', e) 63 + }) 64 + .onEnd(e => { 65 + events.emit('end', e) 66 + }) 67 + .onFinalize(e => { 68 + events.emit('finalize', e) 69 + }) 70 + 71 + return ( 72 + <Context.Provider value={ctx}> 73 + <GestureDetector gesture={gesture}>{children}</GestureDetector> 74 + </Context.Provider> 75 + ) 76 + } 77 + 78 + export function useGlobalGestureEvents() { 79 + return useContext(Context) 80 + }
+9
src/state/global-gesture-events/index.web.tsx
··· 1 + export function GlobalGestureEventsProvider(_props: { 2 + children: React.ReactNode 3 + }) { 4 + throw new Error('GlobalGestureEventsProvider is not supported on web.') 5 + } 6 + 7 + export function useGlobalGestureEvents() { 8 + throw new Error('useGlobalGestureEvents is not supported on web.') 9 + }
-86
src/state/shell/GlobalGestureEvents.tsx
··· 1 - import {createContext, useContext, useMemo, useEffect, useRef, useState} from 'react' 2 - import EventEmitter from 'eventemitter3' 3 - import { 4 - GestureDetector, 5 - Gesture, 6 - GestureStateChangeEvent, 7 - GestureUpdateEvent, 8 - PanGestureHandlerEventPayload, 9 - } from 'react-native-gesture-handler' 10 - 11 - const events = new EventEmitter<{ 12 - begin: GestureStateChangeEvent<PanGestureHandlerEventPayload> 13 - update: GestureUpdateEvent<PanGestureHandlerEventPayload> 14 - end: GestureStateChangeEvent<PanGestureHandlerEventPayload> 15 - finalize: GestureStateChangeEvent<PanGestureHandlerEventPayload> 16 - }>() 17 - 18 - const Context = createContext<{ 19 - register: () => void 20 - unregister: () => void 21 - }>({ 22 - register: () => {}, 23 - unregister: () => {}, 24 - }) 25 - 26 - export function GlobalGestureEvents({ 27 - children, 28 - }: { 29 - children: React.ReactNode 30 - }): React.ReactElement { 31 - const refCount = useRef(0) 32 - const [enabled, setEnabled] = useState(false) 33 - const ctx = useMemo(() => ({ 34 - register() { 35 - refCount.current += 1 36 - if (refCount.current === 1) { 37 - setEnabled(true) 38 - } 39 - }, 40 - unregister() { 41 - refCount.current -= 1 42 - if (refCount.current === 0) { 43 - setEnabled(false) 44 - } 45 - }, 46 - }), [setEnabled]) 47 - const gesture = Gesture.Pan() 48 - .runOnJS(true) 49 - .enabled(enabled) 50 - .simultaneousWithExternalGesture() 51 - .onBegin(e => { 52 - events.emit('begin', e) 53 - }) 54 - .onUpdate(e => { 55 - events.emit('update', e) 56 - }) 57 - .onEnd(e => { 58 - events.emit('end', e) 59 - }) 60 - .onFinalize(e => { 61 - events.emit('finalize', e) 62 - }) 63 - 64 - return ( 65 - <Context.Provider value={ctx}> 66 - <GestureDetector gesture={gesture}>{children}</GestureDetector> 67 - </Context.Provider> 68 - ) 69 - } 70 - 71 - export function useOnInteract( 72 - onInteract: ( 73 - e: GestureStateChangeEvent<PanGestureHandlerEventPayload>, 74 - ) => void, 75 - ) { 76 - const ctx = useContext(Context) 77 - useEffect(() => { 78 - ctx.register() 79 - events.on('begin', onInteract) 80 - 81 - return () => { 82 - ctx.unregister() 83 - events.off('begin', onInteract) 84 - } 85 - }, [ctx, onInteract]) 86 - }