UNPKG

@oxyhq/services

Version:

OxyHQ Expo/React Native SDK — UI components, screens, and native features

41 lines (40 loc) 1.28 kB
"use strict"; import React, { useState, forwardRef } from 'react'; import { ScrollView, StyleSheet } from 'react-native'; import { jsx as _jsx } from "react/jsx-runtime"; /** * A ScrollView that automatically adjusts its height to match its content, * but shrinks if constrained by a parent (e.g., a Max Height Bottom Sheet). * * This solves the "collapsed to 0 height" issue when using ScrollView inside an auto-height container. */ export const AutoHeightScrollView = /*#__PURE__*/forwardRef((props, ref) => { const [contentHeight, setContentHeight] = useState(0); const { style, onContentSizeChange, ...rest } = props; const handleContentSizeChange = (w, h) => { setContentHeight(h); onContentSizeChange?.(w, h); }; return /*#__PURE__*/_jsx(ScrollView, { ref: ref, style: [styles.defaultStyle, style, { height: contentHeight > 0 ? contentHeight : undefined }], onContentSizeChange: handleContentSizeChange, ...rest }); }); const styles = StyleSheet.create({ defaultStyle: { flexShrink: 1, flexGrow: 0, // Ensure we don't force expansion beyond content unless needed minHeight: 0 } }); AutoHeightScrollView.displayName = 'AutoHeightScrollView'; //# sourceMappingURL=AutoHeightScrollView.js.map