/** * Side-effect module — importing it monkey-patches `Field` with mobile-specific measurement and scroll implementations. It must be imported (via `packages/mobile/src/index.ts`) before any form field renders; the form package ships no-op stubs for these methods by default so a missing import would silently fail to scroll to validation errors. */ import React from 'react' import { Field } from '@codeleap/form' import { StatusBar, View } from 'react-native' import { Scrollable } from './scroll' Field.methodGetPadding = (field) => { return StatusBar.currentHeight - 16 } Field.methodMeasurePosition = (field, wrapperRef: React.MutableRefObject) => { return new Promise((resolve, reject) => { wrapperRef.current.measure( (x, y, width, height, pageX, pageY) => { resolve({ x, y, width, height, pageX, pageY }) } ) }) } Field.methodScrollTo = (field, scrollRef: React.MutableRefObject, measure) => { return new Promise((resolve, reject) => { const target = measure?.pageY - field.getPadding() const unsub = scrollRef.current.subscribe('onMomentumScrollEnd', e => { resolve(null) unsub() }) scrollRef.current.scrollTo({ y: target, animated: true, }) }) }