(ctx: StateContext, { stylePaddingTop }: { stylePaddingTop?: number })
| 1 | import { peek$, type StateContext, set$ } from "@/state/state"; |
| 2 | |
| 3 | export 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 | } |
no test coverage detected