tweak rendering

This commit is contained in:
Hailey
2024-08-20 08:57:44 -07:00
parent f3ade055e9
commit a1d2f670fb
2 changed files with 81 additions and 100 deletions
+19 -34
View File
@@ -33,6 +33,8 @@ const Context = React.createContext<Context>({
}, },
}) })
export const useScreenHider = () => React.useContext(Context)
export function Outer({ export function Outer({
modui, modui,
children, children,
@@ -44,40 +46,33 @@ export function Outer({
const [isContentVisible, setIsContentVisible] = React.useState(!blur) const [isContentVisible, setIsContentVisible] = React.useState(!blur)
const info = useModerationCauseDescription(blur) const info = useModerationCauseDescription(blur)
const meta = React.useMemo( const meta = {
() => ({ isNoPwi: Boolean(
isNoPwi: !!modui.blurs.find( modui.blurs.find(
cause => cause =>
cause.type === 'label' && cause.type === 'label' &&
cause.labelDef.identifier === '!no-unauthenticated', cause.labelDef.identifier === '!no-unauthenticated',
), ),
),
noOverride: modui.noOverride, noOverride: modui.noOverride,
}), }
[modui],
)
const showInfoDialog = React.useCallback(() => { const showInfoDialog = () => {
control.open() control.open()
}, [control]) }
const onSetContentVisible = React.useCallback( const onSetContentVisible = (show: boolean) => {
(show: boolean) => {
if (meta.noOverride) return if (meta.noOverride) return
setIsContentVisible(show) setIsContentVisible(show)
}, }
[setIsContentVisible, meta],
)
const ctx = React.useMemo( const ctx = {
() => ({
isContentVisible, isContentVisible,
setIsContentVisible: onSetContentVisible, setIsContentVisible: onSetContentVisible,
showInfoDialog, showInfoDialog,
info, info,
meta, meta,
}), }
[isContentVisible, onSetContentVisible, info, meta, showInfoDialog],
)
return ( return (
<Context.Provider value={ctx}> <Context.Provider value={ctx}>
@@ -87,22 +82,12 @@ export function Outer({
) )
} }
export function Content({ export function Content({children}: {children: React.ReactNode}) {
children, const ctx = useScreenHider()
}: { return ctx.isContentVisible ? children : null
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({ export function Mask({children}: {children: React.ReactNode}) {
children, const ctx = useScreenHider()
}: { return ctx.isContentVisible ? null : children
children: (context: Context) => React.ReactNode
}) {
const ctx = React.useContext(Context)
const child = React.useMemo(() => children(ctx), [ctx, children])
return !ctx.isContentVisible ? child : null
} }
+2 -6
View File
@@ -193,10 +193,9 @@ function ProfileListScreenLoaded({
return ( return (
<Hider.Outer modui={moderation.ui('contentView')}> <Hider.Outer modui={moderation.ui('contentView')}>
<Hider.Mask> <Hider.Mask>
{() => <ListHiddenScreen list={list} preferences={preferences} />} <ListHiddenScreen list={list} preferences={preferences} />
</Hider.Mask> </Hider.Mask>
<Hider.Content> <Hider.Content>
{() => (
<View style={s.hContentRegion}> <View style={s.hContentRegion}>
<PagerWithHeader <PagerWithHeader
items={SECTION_TITLES_CURATE} items={SECTION_TITLES_CURATE}
@@ -237,7 +236,6 @@ function ProfileListScreenLoaded({
accessibilityHint="" accessibilityHint=""
/> />
</View> </View>
)}
</Hider.Content> </Hider.Content>
</Hider.Outer> </Hider.Outer>
) )
@@ -245,10 +243,9 @@ function ProfileListScreenLoaded({
return ( return (
<Hider.Outer modui={moderation.ui('contentView')}> <Hider.Outer modui={moderation.ui('contentView')}>
<Hider.Mask> <Hider.Mask>
{() => <ListHiddenScreen list={list} preferences={preferences} />} <ListHiddenScreen list={list} preferences={preferences} />
</Hider.Mask> </Hider.Mask>
<Hider.Content> <Hider.Content>
{() => (
<View style={s.hContentRegion}> <View style={s.hContentRegion}>
<PagerWithHeader <PagerWithHeader
items={SECTION_TITLES_MOD} items={SECTION_TITLES_MOD}
@@ -278,7 +275,6 @@ function ProfileListScreenLoaded({
accessibilityHint="" accessibilityHint=""
/> />
</View> </View>
)}
</Hider.Content> </Hider.Content>
</Hider.Outer> </Hider.Outer>
) )