@impulse-ui-native/scroll-view 15.0.4 → 16.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +64 -64
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -1,64 +1,64 @@
|
|
|
1
|
-
# @impulse-ui-native/scroll-view
|
|
2
|
-
|
|
3
|
-
Native React Native ScrollView and a small hook to reveal an initially selected child with its actual measured size.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
```sh
|
|
8
|
-
pnpm add @impulse-ui-native/scroll-view
|
|
9
|
-
```
|
|
10
|
-
|
|
11
|
-
React and React Native are peer dependencies. No theme provider is required. The toolkit also exports this package.
|
|
12
|
-
|
|
13
|
-
## Usage
|
|
14
|
-
|
|
15
|
-
```tsx
|
|
16
|
-
import { useRef } from "react";
|
|
17
|
-
import { Pressable, Text } from "react-native";
|
|
18
|
-
|
|
19
|
-
import {
|
|
20
|
-
ScrollView,
|
|
21
|
-
useScrollViewInitialScroll,
|
|
22
|
-
} from "@impulse-ui-native/scroll-view";
|
|
23
|
-
|
|
24
|
-
function Options({ items, selectedValue }) {
|
|
25
|
-
const initialValue = useRef(selectedValue).current;
|
|
26
|
-
const scroll = useScrollViewInitialScroll({ horizontal: true });
|
|
27
|
-
|
|
28
|
-
return (
|
|
29
|
-
<ScrollView
|
|
30
|
-
ref={scroll.scrollViewRef}
|
|
31
|
-
horizontal
|
|
32
|
-
onLayout={scroll.onLayout}
|
|
33
|
-
onContentSizeChange={scroll.onContentSizeChange}
|
|
34
|
-
onScrollBeginDrag={scroll.onScrollBeginDrag}
|
|
35
|
-
>
|
|
36
|
-
{items.map((item) => (
|
|
37
|
-
<Pressable
|
|
38
|
-
key={item.value}
|
|
39
|
-
ref={item.value === initialValue ? scroll.targetRef : undefined}
|
|
40
|
-
onLayout={
|
|
41
|
-
item.value === initialValue ? scroll.onTargetLayout : undefined
|
|
42
|
-
}
|
|
43
|
-
>
|
|
44
|
-
<Text>{item.label}</Text>
|
|
45
|
-
</Pressable>
|
|
46
|
-
))}
|
|
47
|
-
</ScrollView>
|
|
48
|
-
);
|
|
49
|
-
}
|
|
50
|
-
```
|
|
51
|
-
|
|
52
|
-
The hook waits for viewport, content, and target layout, then measures the target relative to the native ScrollView with `measureLayout`. This uses layout coordinates rather than the current visual scroll position. Nested native wrappers, padding, gaps, and variable item sizes are included. Attach `targetRef` to one native View or a component forwarding its native View ref. Compose `onTargetLayout` with any existing item layout callback.
|
|
53
|
-
|
|
54
|
-
It scrolls only far enough to reveal the target, without animation. Already visible items retain the initial position; oversized items align at their leading edge. The default axis is vertical; pass `horizontal: true` to the hook and ScrollView for horizontal content.
|
|
55
|
-
|
|
56
|
-
Pass `enabled: false` to skip positioning. Pass native `contentOffset` to both the hook and ScrollView to preserve an explicit starting position. Existing `onLayout`, `onContentSizeChange`, and `onScrollBeginDrag` callbacks can be passed to the hook; its returned handlers invoke them with the original arguments. Other native props remain available because `ScrollView` is the native component.
|
|
57
|
-
|
|
58
|
-
Positioning happens once per mount. A user drag cancels pending positioning. Later selection and layout changes do not scroll again. Mount with the initial selection and content available, and remount when a fresh initial position is needed. This hook is for ordinary, unzoomed ScrollViews without automatic/custom content insets or snapping.
|
|
59
|
-
|
|
60
|
-
Exports: `ScrollView`, `ScrollViewProps`, `useScrollViewInitialScroll`, and `UseScrollViewInitialScrollOptions`.
|
|
61
|
-
|
|
62
|
-
## Agent and design reference
|
|
63
|
-
|
|
64
|
-
Start with the [capability guide](../../docs/design-system/capabilities/scroll-view.md) for supported exports, props, defaults, composition rules, setup, and recipes. Use the [component chooser](../../docs/design-system/component-chooser.md) to select a package. These references describe the repository source; verify your installed package version before copying examples.
|
|
1
|
+
# @impulse-ui-native/scroll-view
|
|
2
|
+
|
|
3
|
+
Native React Native ScrollView and a small hook to reveal an initially selected child with its actual measured size.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @impulse-ui-native/scroll-view
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
React and React Native are peer dependencies. No theme provider is required. The toolkit also exports this package.
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
import { useRef } from "react";
|
|
17
|
+
import { Pressable, Text } from "react-native";
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
ScrollView,
|
|
21
|
+
useScrollViewInitialScroll,
|
|
22
|
+
} from "@impulse-ui-native/scroll-view";
|
|
23
|
+
|
|
24
|
+
function Options({ items, selectedValue }) {
|
|
25
|
+
const initialValue = useRef(selectedValue).current;
|
|
26
|
+
const scroll = useScrollViewInitialScroll({ horizontal: true });
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<ScrollView
|
|
30
|
+
ref={scroll.scrollViewRef}
|
|
31
|
+
horizontal
|
|
32
|
+
onLayout={scroll.onLayout}
|
|
33
|
+
onContentSizeChange={scroll.onContentSizeChange}
|
|
34
|
+
onScrollBeginDrag={scroll.onScrollBeginDrag}
|
|
35
|
+
>
|
|
36
|
+
{items.map((item) => (
|
|
37
|
+
<Pressable
|
|
38
|
+
key={item.value}
|
|
39
|
+
ref={item.value === initialValue ? scroll.targetRef : undefined}
|
|
40
|
+
onLayout={
|
|
41
|
+
item.value === initialValue ? scroll.onTargetLayout : undefined
|
|
42
|
+
}
|
|
43
|
+
>
|
|
44
|
+
<Text>{item.label}</Text>
|
|
45
|
+
</Pressable>
|
|
46
|
+
))}
|
|
47
|
+
</ScrollView>
|
|
48
|
+
);
|
|
49
|
+
}
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
The hook waits for viewport, content, and target layout, then measures the target relative to the native ScrollView with `measureLayout`. This uses layout coordinates rather than the current visual scroll position. Nested native wrappers, padding, gaps, and variable item sizes are included. Attach `targetRef` to one native View or a component forwarding its native View ref. Compose `onTargetLayout` with any existing item layout callback.
|
|
53
|
+
|
|
54
|
+
It scrolls only far enough to reveal the target, without animation. Already visible items retain the initial position; oversized items align at their leading edge. The default axis is vertical; pass `horizontal: true` to the hook and ScrollView for horizontal content.
|
|
55
|
+
|
|
56
|
+
Pass `enabled: false` to skip positioning. Pass native `contentOffset` to both the hook and ScrollView to preserve an explicit starting position. Existing `onLayout`, `onContentSizeChange`, and `onScrollBeginDrag` callbacks can be passed to the hook; its returned handlers invoke them with the original arguments. Other native props remain available because `ScrollView` is the native component.
|
|
57
|
+
|
|
58
|
+
Positioning happens once per mount. A user drag cancels pending positioning. Later selection and layout changes do not scroll again. Mount with the initial selection and content available, and remount when a fresh initial position is needed. This hook is for ordinary, unzoomed ScrollViews without automatic/custom content insets or snapping.
|
|
59
|
+
|
|
60
|
+
Exports: `ScrollView`, `ScrollViewProps`, `useScrollViewInitialScroll`, and `UseScrollViewInitialScrollOptions`.
|
|
61
|
+
|
|
62
|
+
## Agent and design reference
|
|
63
|
+
|
|
64
|
+
Start with the [capability guide](../../docs/design-system/capabilities/scroll-view.md) for supported exports, props, defaults, composition rules, setup, and recipes. Use the [component chooser](../../docs/design-system/component-chooser.md) to select a package. These references describe the repository source; verify your installed package version before copying examples.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@impulse-ui-native/scroll-view",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"description": "Native ScrollView and a small hook to reveal an initially selected child.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -45,7 +45,7 @@
|
|
|
45
45
|
},
|
|
46
46
|
"prettier": "@impulse-ui-native/prettier-config",
|
|
47
47
|
"dependencies": {
|
|
48
|
-
"@impulse-ui-native/core": "
|
|
48
|
+
"@impulse-ui-native/core": "16.0.0"
|
|
49
49
|
},
|
|
50
50
|
"scripts": {
|
|
51
51
|
"build": "tsup --config tsup.config.ts",
|