From a1d2f670fb416bb1d43d2bf43e6fc01a6da32eb0 Mon Sep 17 00:00:00 2001 From: Hailey Date: Tue, 20 Aug 2024 08:57:44 -0700 Subject: [PATCH] tweak rendering --- src/components/moderation/Hider.tsx | 69 +++++++---------- src/view/screens/ProfileList.tsx | 112 ++++++++++++++-------------- 2 files changed, 81 insertions(+), 100 deletions(-) diff --git a/src/components/moderation/Hider.tsx b/src/components/moderation/Hider.tsx index caf76d51c6..7acc7bb949 100644 --- a/src/components/moderation/Hider.tsx +++ b/src/components/moderation/Hider.tsx @@ -33,6 +33,8 @@ const Context = React.createContext({ }, }) +export const useScreenHider = () => React.useContext(Context) + export function Outer({ modui, children, @@ -44,40 +46,33 @@ export function Outer({ const [isContentVisible, setIsContentVisible] = React.useState(!blur) const info = useModerationCauseDescription(blur) - const meta = React.useMemo( - () => ({ - isNoPwi: !!modui.blurs.find( + const meta = { + isNoPwi: Boolean( + modui.blurs.find( cause => cause.type === 'label' && cause.labelDef.identifier === '!no-unauthenticated', ), - noOverride: modui.noOverride, - }), - [modui], - ) + ), + noOverride: modui.noOverride, + } - const showInfoDialog = React.useCallback(() => { + const showInfoDialog = () => { control.open() - }, [control]) + } - const onSetContentVisible = React.useCallback( - (show: boolean) => { - if (meta.noOverride) return - setIsContentVisible(show) - }, - [setIsContentVisible, meta], - ) + const onSetContentVisible = (show: boolean) => { + if (meta.noOverride) return + setIsContentVisible(show) + } - const ctx = React.useMemo( - () => ({ - isContentVisible, - setIsContentVisible: onSetContentVisible, - showInfoDialog, - info, - meta, - }), - [isContentVisible, onSetContentVisible, info, meta, showInfoDialog], - ) + const ctx = { + isContentVisible, + setIsContentVisible: onSetContentVisible, + showInfoDialog, + info, + meta, + } return ( @@ -87,22 +82,12 @@ export function Outer({ ) } -export function Content({ - children, -}: { - children: (context: Context) => React.ReactNode -}) { - const ctx = React.useContext(Context) - const child = React.useMemo(() => children(ctx), [ctx, children]) - return ctx.isContentVisible ? child : null +export function Content({children}: {children: React.ReactNode}) { + const ctx = useScreenHider() + return ctx.isContentVisible ? children : null } -export function Mask({ - children, -}: { - children: (context: Context) => React.ReactNode -}) { - const ctx = React.useContext(Context) - const child = React.useMemo(() => children(ctx), [ctx, children]) - return !ctx.isContentVisible ? child : null +export function Mask({children}: {children: React.ReactNode}) { + const ctx = useScreenHider() + return ctx.isContentVisible ? null : children } diff --git a/src/view/screens/ProfileList.tsx b/src/view/screens/ProfileList.tsx index 3b3d2ec5c6..727ab4b6dd 100644 --- a/src/view/screens/ProfileList.tsx +++ b/src/view/screens/ProfileList.tsx @@ -193,71 +193,29 @@ function ProfileListScreenLoaded({ return ( - {() => } + - {() => ( - - - {({headerHeight, scrollElRef, isFocused}) => ( - - )} - {({headerHeight, scrollElRef}) => ( - - )} - - openComposer({})} - icon={ - - } - accessibilityRole="button" - accessibilityLabel={_(msg`New post`)} - accessibilityHint="" - /> - - )} - - - ) - } - return ( - - - {() => } - - - {() => ( + renderHeader={renderHeader} + onCurrentPageSelected={onCurrentPageSelected}> + {({headerHeight, scrollElRef, isFocused}) => ( + + )} {({headerHeight, scrollElRef}) => ( @@ -278,7 +236,45 @@ function ProfileListScreenLoaded({ accessibilityHint="" /> - )} + + + ) + } + return ( + + + + + + + + {({headerHeight, scrollElRef}) => ( + + )} + + openComposer({})} + icon={ + + } + accessibilityRole="button" + accessibilityLabel={_(msg`New post`)} + accessibilityHint="" + /> + )