MCPcopy
hub / github.com/LegendApp/legend-list / setPaddingTop

Function setPaddingTop

src/utils/setPaddingTop.ts:3–23  ·  view source on GitHub ↗
(ctx: StateContext, { stylePaddingTop }: { stylePaddingTop?: number })

Source from the content-addressed store, hash-verified

1import { peek$, type StateContext, set$ } from "@/state/state";
2
3export function setPaddingTop(ctx: StateContext, { stylePaddingTop }: { stylePaddingTop?: number }) {
4 const state = ctx.state;
5 if (stylePaddingTop !== undefined) {
6 const prevStylePaddingTop = peek$(ctx, "stylePaddingTop") || 0;
7 if (stylePaddingTop < prevStylePaddingTop) {
8 // If reducing top padding then we need to make sure the ScrollView doesn't
9 // scroll itself because the height reduced.
10 // First add the padding to the total size so that the total height in the ScrollView
11 // doesn't change
12 let prevTotalSize = peek$(ctx, "totalSize") || 0;
13 set$(ctx, "totalSize", prevTotalSize + prevStylePaddingTop);
14 state.timeoutSetPaddingTop = setTimeout(() => {
15 prevTotalSize = peek$(ctx, "totalSize") || 0;
16 set$(ctx, "totalSize", prevTotalSize - prevStylePaddingTop);
17 }, 16);
18 }
19
20 // Now set the padding
21 set$(ctx, "stylePaddingTop", stylePaddingTop);
22 }
23}

Callers 2

initializeStateVarsFunction · 0.90

Calls 2

peek$Function · 0.90
set$Function · 0.90

Tested by

no test coverage detected