@rific/scroll-view 0.9.2 → 1.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 +22 -1
- package/dist/index.d.mts +18 -1
- package/dist/index.d.ts +18 -1
- package/dist/index.js +17 -2
- package/dist/index.mjs +14 -2
- package/package.json +1 -1
- package/src/ScrollViewConfig.tsx +34 -0
- package/src/ScrollViewHeader.tsx +9 -3
- package/src/index.ts +2 -0
package/README.md
CHANGED
|
@@ -63,6 +63,27 @@ App-wide defaults for scroll settings. Wrap your root layout to set global defau
|
|
|
63
63
|
|
|
64
64
|
---
|
|
65
65
|
|
|
66
|
+
### `ScrollViewConfigProvider`
|
|
67
|
+
|
|
68
|
+
App-wide component config, set once at startup. Today it holds one thing: the component `ScrollViewHeader` renders for a `backAction` callback. Pass `AppbarBackAction` from [`@rific/feedback-press`](https://www.npmjs.com/package/@rific/feedback-press) and every header's back button gets the same haptics and sound as the rest of your buttons, without touching each screen. This package doesn't depend on feedback-press; you hand it the component.
|
|
69
|
+
|
|
70
|
+
| Prop | Type | Default | Description |
|
|
71
|
+
|------|------|---------|-------------|
|
|
72
|
+
| `BackAction` | `ComponentType<ScrollViewBackActionProps>` | Paper's `Appbar.BackAction` | Rendered for a `backAction` callback. Receives `onPress`, `size`, `style` and `accessibilityLabel` (from `backActionAccessibilityLabel`), the same props the default gets |
|
|
73
|
+
| `children` | `ReactNode` | - | - |
|
|
74
|
+
|
|
75
|
+
```tsx
|
|
76
|
+
import { AppbarBackAction } from '@rific/feedback-press'
|
|
77
|
+
import { ScrollViewConfigProvider } from '@rific/scroll-view'
|
|
78
|
+
|
|
79
|
+
// Inside FeedbackPressProvider, since AppbarBackAction reads it
|
|
80
|
+
<ScrollViewConfigProvider BackAction={AppbarBackAction}>{children}</ScrollViewConfigProvider>
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
Or call `configureScrollView({ BackAction: AppbarBackAction })` once at module load; `getScrollViewConfig()` reads it back. Like the other `@rific` module configs (`DrawerProvider`, `ResizableInputProvider`), this is plain startup config, not React state: the provider sets it during its own render, before anything under it renders, and changing it later doesn't re-render headers already on screen. A `backAction` element on one header still replaces the configured component there.
|
|
84
|
+
|
|
85
|
+
---
|
|
86
|
+
|
|
66
87
|
### `ScrollViewProvider`
|
|
67
88
|
|
|
68
89
|
Screen-level provider that owns header/footer state and scroll position. Must wrap `ScrollViewHeader`, `ScrollViewFooter`, and the scroll component.
|
|
@@ -108,7 +129,7 @@ Floating header with blur backdrop, title, back action, trailing action, and bui
|
|
|
108
129
|
| `caption` | `string` | - | Subtitle below title |
|
|
109
130
|
| `centerContent` | `ReactNode` | - | Replaces title/caption with custom content |
|
|
110
131
|
| `children` | `ReactNode` | - | Left-side content (icon buttons, etc.) |
|
|
111
|
-
| `backAction` | `() => void` | - |
|
|
132
|
+
| `backAction` | `(() => void) \| ReactNode` | - | A callback renders a back button (the [configured `BackAction`](#scrollviewconfigprovider), Paper's `Appbar.BackAction` by default) and calls it on press. An element is rendered in that spot instead |
|
|
112
133
|
| `backActionFixed` | `boolean` | settings | Keep back button visible as header scrolls away |
|
|
113
134
|
| `trailingAction` | `ReactNode` | - | Right-side floating action |
|
|
114
135
|
| `trailingActionFixed` | `boolean` | `true` | Keep trailing action visible as header scrolls away |
|
package/dist/index.d.mts
CHANGED
|
@@ -166,6 +166,23 @@ type ScrollViewChromeProviderProps = {
|
|
|
166
166
|
};
|
|
167
167
|
declare const ScrollViewChromeProvider: ({ children, footprint, overhang, snapBack, useIsActive }: ScrollViewChromeProviderProps) => react.JSX.Element;
|
|
168
168
|
|
|
169
|
+
type ScrollViewBackActionProps = {
|
|
170
|
+
accessibilityLabel?: string;
|
|
171
|
+
onPress: () => void;
|
|
172
|
+
size: number;
|
|
173
|
+
style: ViewStyle;
|
|
174
|
+
};
|
|
175
|
+
type ScrollViewConfig = {
|
|
176
|
+
/** Component ScrollViewHeader renders when `backAction` is a plain callback. Pass `AppbarBackAction` from `@rific/feedback-press` to give every header's back button its haptics and sound; omit to keep react-native-paper's `Appbar.BackAction`. A `backAction` element on one header still replaces it there. */
|
|
177
|
+
BackAction?: ComponentType<ScrollViewBackActionProps>;
|
|
178
|
+
};
|
|
179
|
+
declare const configureScrollView: (next: Partial<ScrollViewConfig>) => void;
|
|
180
|
+
declare const getScrollViewConfig: () => ScrollViewConfig;
|
|
181
|
+
declare const ScrollViewConfigProvider: (props: _rific_core.ModuleConfigProviderProps<ScrollViewConfig>) => React.JSX.Element;
|
|
182
|
+
type ScrollViewConfigProviderProps = ScrollViewConfig & {
|
|
183
|
+
children: ReactNode;
|
|
184
|
+
};
|
|
185
|
+
|
|
169
186
|
type ScrollViewContextType = {
|
|
170
187
|
blur: boolean;
|
|
171
188
|
chromeHosted: boolean;
|
|
@@ -285,4 +302,4 @@ declare const useScrollViewChromeReveal: () => () => void;
|
|
|
285
302
|
|
|
286
303
|
declare const useScrollViewSettings: () => _rific_core.SettingsContextValue<ScrollViewSettings>;
|
|
287
304
|
|
|
288
|
-
export { type ChipProps, CustomList, type CustomListProps, FlatList, type FlatListProps, PullSearch, type PullSearchHandle, type PullSearchProps, ScrollView, ScrollViewChromeProvider, type ScrollViewChromeProviderProps, ScrollViewContext, type ScrollViewContextType, ScrollViewFooter, type ScrollViewFooterProps, ScrollViewHeader, type ScrollViewHeaderProps, type ScrollViewProps, ScrollViewProvider, type ScrollViewProviderProps, type ScrollViewSettings, ScrollViewSettingsContext, type ScrollViewSettingsContextType, ScrollViewSettingsProvider, type ScrollViewSettingsProviderProps, SectionList, type SectionListProps, defaultScrollViewSettings, scrollViewActions, scrollViewReducer, useKeyboardInset, useScrollView, useScrollViewChromePin, useScrollViewChromeReveal, useScrollViewChromeStyle, useScrollViewSettings };
|
|
305
|
+
export { type ChipProps, CustomList, type CustomListProps, FlatList, type FlatListProps, PullSearch, type PullSearchHandle, type PullSearchProps, ScrollView, type ScrollViewBackActionProps, ScrollViewChromeProvider, type ScrollViewChromeProviderProps, type ScrollViewConfig, ScrollViewConfigProvider, type ScrollViewConfigProviderProps, ScrollViewContext, type ScrollViewContextType, ScrollViewFooter, type ScrollViewFooterProps, ScrollViewHeader, type ScrollViewHeaderProps, type ScrollViewProps, ScrollViewProvider, type ScrollViewProviderProps, type ScrollViewSettings, ScrollViewSettingsContext, type ScrollViewSettingsContextType, ScrollViewSettingsProvider, type ScrollViewSettingsProviderProps, SectionList, type SectionListProps, configureScrollView, defaultScrollViewSettings, getScrollViewConfig, scrollViewActions, scrollViewReducer, useKeyboardInset, useScrollView, useScrollViewChromePin, useScrollViewChromeReveal, useScrollViewChromeStyle, useScrollViewSettings };
|
package/dist/index.d.ts
CHANGED
|
@@ -166,6 +166,23 @@ type ScrollViewChromeProviderProps = {
|
|
|
166
166
|
};
|
|
167
167
|
declare const ScrollViewChromeProvider: ({ children, footprint, overhang, snapBack, useIsActive }: ScrollViewChromeProviderProps) => react.JSX.Element;
|
|
168
168
|
|
|
169
|
+
type ScrollViewBackActionProps = {
|
|
170
|
+
accessibilityLabel?: string;
|
|
171
|
+
onPress: () => void;
|
|
172
|
+
size: number;
|
|
173
|
+
style: ViewStyle;
|
|
174
|
+
};
|
|
175
|
+
type ScrollViewConfig = {
|
|
176
|
+
/** Component ScrollViewHeader renders when `backAction` is a plain callback. Pass `AppbarBackAction` from `@rific/feedback-press` to give every header's back button its haptics and sound; omit to keep react-native-paper's `Appbar.BackAction`. A `backAction` element on one header still replaces it there. */
|
|
177
|
+
BackAction?: ComponentType<ScrollViewBackActionProps>;
|
|
178
|
+
};
|
|
179
|
+
declare const configureScrollView: (next: Partial<ScrollViewConfig>) => void;
|
|
180
|
+
declare const getScrollViewConfig: () => ScrollViewConfig;
|
|
181
|
+
declare const ScrollViewConfigProvider: (props: _rific_core.ModuleConfigProviderProps<ScrollViewConfig>) => React.JSX.Element;
|
|
182
|
+
type ScrollViewConfigProviderProps = ScrollViewConfig & {
|
|
183
|
+
children: ReactNode;
|
|
184
|
+
};
|
|
185
|
+
|
|
169
186
|
type ScrollViewContextType = {
|
|
170
187
|
blur: boolean;
|
|
171
188
|
chromeHosted: boolean;
|
|
@@ -285,4 +302,4 @@ declare const useScrollViewChromeReveal: () => () => void;
|
|
|
285
302
|
|
|
286
303
|
declare const useScrollViewSettings: () => _rific_core.SettingsContextValue<ScrollViewSettings>;
|
|
287
304
|
|
|
288
|
-
export { type ChipProps, CustomList, type CustomListProps, FlatList, type FlatListProps, PullSearch, type PullSearchHandle, type PullSearchProps, ScrollView, ScrollViewChromeProvider, type ScrollViewChromeProviderProps, ScrollViewContext, type ScrollViewContextType, ScrollViewFooter, type ScrollViewFooterProps, ScrollViewHeader, type ScrollViewHeaderProps, type ScrollViewProps, ScrollViewProvider, type ScrollViewProviderProps, type ScrollViewSettings, ScrollViewSettingsContext, type ScrollViewSettingsContextType, ScrollViewSettingsProvider, type ScrollViewSettingsProviderProps, SectionList, type SectionListProps, defaultScrollViewSettings, scrollViewActions, scrollViewReducer, useKeyboardInset, useScrollView, useScrollViewChromePin, useScrollViewChromeReveal, useScrollViewChromeStyle, useScrollViewSettings };
|
|
305
|
+
export { type ChipProps, CustomList, type CustomListProps, FlatList, type FlatListProps, PullSearch, type PullSearchHandle, type PullSearchProps, ScrollView, type ScrollViewBackActionProps, ScrollViewChromeProvider, type ScrollViewChromeProviderProps, type ScrollViewConfig, ScrollViewConfigProvider, type ScrollViewConfigProviderProps, ScrollViewContext, type ScrollViewContextType, ScrollViewFooter, type ScrollViewFooterProps, ScrollViewHeader, type ScrollViewHeaderProps, type ScrollViewProps, ScrollViewProvider, type ScrollViewProviderProps, type ScrollViewSettings, ScrollViewSettingsContext, type ScrollViewSettingsContextType, ScrollViewSettingsProvider, type ScrollViewSettingsProviderProps, SectionList, type SectionListProps, configureScrollView, defaultScrollViewSettings, getScrollViewConfig, scrollViewActions, scrollViewReducer, useKeyboardInset, useScrollView, useScrollViewChromePin, useScrollViewChromeReveal, useScrollViewChromeStyle, useScrollViewSettings };
|
package/dist/index.js
CHANGED
|
@@ -35,6 +35,7 @@ __export(index_exports, {
|
|
|
35
35
|
PullSearch: () => PullSearch,
|
|
36
36
|
ScrollView: () => ScrollView,
|
|
37
37
|
ScrollViewChromeProvider: () => ScrollViewChromeProvider,
|
|
38
|
+
ScrollViewConfigProvider: () => ScrollViewConfigProvider,
|
|
38
39
|
ScrollViewContext: () => ScrollViewContext,
|
|
39
40
|
ScrollViewFooter: () => ScrollViewFooter,
|
|
40
41
|
ScrollViewHeader: () => ScrollViewHeader,
|
|
@@ -42,7 +43,9 @@ __export(index_exports, {
|
|
|
42
43
|
ScrollViewSettingsContext: () => ScrollViewSettingsContext,
|
|
43
44
|
ScrollViewSettingsProvider: () => ScrollViewSettingsProvider,
|
|
44
45
|
SectionList: () => SectionList,
|
|
46
|
+
configureScrollView: () => configureScrollView,
|
|
45
47
|
defaultScrollViewSettings: () => defaultScrollViewSettings,
|
|
48
|
+
getScrollViewConfig: () => getScrollViewConfig,
|
|
46
49
|
scrollViewActions: () => scrollViewActions,
|
|
47
50
|
scrollViewReducer: () => scrollViewReducer,
|
|
48
51
|
useKeyboardInset: () => useKeyboardInset,
|
|
@@ -1131,6 +1134,13 @@ var ScrollViewChromeProvider = ({ children, footprint, overhang = 0, snapBack =
|
|
|
1131
1134
|
return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ScrollViewChromeContext.Provider, { value: chrome, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(ScrollViewChromeHostContext.Provider, { value: host, children }) });
|
|
1132
1135
|
};
|
|
1133
1136
|
|
|
1137
|
+
// src/ScrollViewConfig.tsx
|
|
1138
|
+
var import_core3 = require("@rific/core");
|
|
1139
|
+
var scrollViewConfig = (0, import_core3.createModuleConfig)();
|
|
1140
|
+
var configureScrollView = scrollViewConfig.configure;
|
|
1141
|
+
var getScrollViewConfig = scrollViewConfig.getConfig;
|
|
1142
|
+
var ScrollViewConfigProvider = scrollViewConfig.Provider;
|
|
1143
|
+
|
|
1134
1144
|
// src/ScrollViewFooter.tsx
|
|
1135
1145
|
var import_auto_paper3 = require("@rific/auto-paper");
|
|
1136
1146
|
var import_react14 = require("react");
|
|
@@ -1253,6 +1263,8 @@ var ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, backActionAc
|
|
|
1253
1263
|
}, [headerFixed, headerHeightShared, top, headerOffset, pullSearchHeightShared, scrollPosition, snapBackHeaderShared]);
|
|
1254
1264
|
const actionTop = top + actionMargin;
|
|
1255
1265
|
const buttonStyle = { borderRadius: actionSize, height: actionSize, margin: 0, width: actionSize };
|
|
1266
|
+
const BackAction = getScrollViewConfig().BackAction ?? import_react_native_paper4.Appbar.BackAction;
|
|
1267
|
+
const backActionElement = typeof backAction === "function" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BackAction, { accessibilityLabel: backActionAccessibilityLabel, onPress: backAction, size: iconSize ?? actionSize / 2, style: buttonStyle }) : backAction;
|
|
1256
1268
|
const actionShadow = { borderRadius: actionSize / 2, elevation: 2, shadowColor: "#000", shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.15, shadowRadius: 2 };
|
|
1257
1269
|
const leadingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", left: actionMargin, position: "absolute", top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
1258
1270
|
const trailingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", position: "absolute", right: actionMargin, top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
@@ -1272,10 +1284,10 @@ var ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, backActionAc
|
|
|
1272
1284
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_native_reanimated13.default.View, { pointerEvents: "none", style: [styles7.progress, progressStyle], children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(import_react_native_paper4.ProgressBar, { indeterminate: progress === null, visible: progressing, progress: progress ?? void 0 }) }),
|
|
1273
1285
|
backAction && (effectiveBackActionFixed ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_native_reanimated13.default.View, { style: leadingStyle, children: [
|
|
1274
1286
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionBg, { blur, style: actionStyle }),
|
|
1275
|
-
|
|
1287
|
+
backActionElement
|
|
1276
1288
|
] }) : /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_native_reanimated13.default.View, { style: [leadingStyle, translateStyle], children: [
|
|
1277
1289
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionBg, { blur, style: actionStyle }),
|
|
1278
|
-
|
|
1290
|
+
backActionElement
|
|
1279
1291
|
] })),
|
|
1280
1292
|
trailingAction && (trailingActionFixed ? /* @__PURE__ */ (0, import_jsx_runtime10.jsxs)(import_react_native12.View, { style: trailingStyle, children: [
|
|
1281
1293
|
/* @__PURE__ */ (0, import_jsx_runtime10.jsx)(ActionBg, { blur, style: actionStyle }),
|
|
@@ -1743,6 +1755,7 @@ var useScrollViewSettings = scrollViewUseSettings;
|
|
|
1743
1755
|
PullSearch,
|
|
1744
1756
|
ScrollView,
|
|
1745
1757
|
ScrollViewChromeProvider,
|
|
1758
|
+
ScrollViewConfigProvider,
|
|
1746
1759
|
ScrollViewContext,
|
|
1747
1760
|
ScrollViewFooter,
|
|
1748
1761
|
ScrollViewHeader,
|
|
@@ -1750,7 +1763,9 @@ var useScrollViewSettings = scrollViewUseSettings;
|
|
|
1750
1763
|
ScrollViewSettingsContext,
|
|
1751
1764
|
ScrollViewSettingsProvider,
|
|
1752
1765
|
SectionList,
|
|
1766
|
+
configureScrollView,
|
|
1753
1767
|
defaultScrollViewSettings,
|
|
1768
|
+
getScrollViewConfig,
|
|
1754
1769
|
scrollViewActions,
|
|
1755
1770
|
scrollViewReducer,
|
|
1756
1771
|
useKeyboardInset,
|
package/dist/index.mjs
CHANGED
|
@@ -1075,6 +1075,13 @@ var ScrollViewChromeProvider = ({ children, footprint, overhang = 0, snapBack =
|
|
|
1075
1075
|
return /* @__PURE__ */ jsx8(ScrollViewChromeContext.Provider, { value: chrome, children: /* @__PURE__ */ jsx8(ScrollViewChromeHostContext.Provider, { value: host, children }) });
|
|
1076
1076
|
};
|
|
1077
1077
|
|
|
1078
|
+
// src/ScrollViewConfig.tsx
|
|
1079
|
+
import { createModuleConfig } from "@rific/core";
|
|
1080
|
+
var scrollViewConfig = createModuleConfig();
|
|
1081
|
+
var configureScrollView = scrollViewConfig.configure;
|
|
1082
|
+
var getScrollViewConfig = scrollViewConfig.getConfig;
|
|
1083
|
+
var ScrollViewConfigProvider = scrollViewConfig.Provider;
|
|
1084
|
+
|
|
1078
1085
|
// src/ScrollViewFooter.tsx
|
|
1079
1086
|
import { BlurView as BlurView2 } from "@rific/auto-paper";
|
|
1080
1087
|
import { useContext as useContext10, useEffect as useEffect5, useLayoutEffect as useLayoutEffect5, useRef as useRef7 } from "react";
|
|
@@ -1197,6 +1204,8 @@ var ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, backActionAc
|
|
|
1197
1204
|
}, [headerFixed, headerHeightShared, top, headerOffset, pullSearchHeightShared, scrollPosition, snapBackHeaderShared]);
|
|
1198
1205
|
const actionTop = top + actionMargin;
|
|
1199
1206
|
const buttonStyle = { borderRadius: actionSize, height: actionSize, margin: 0, width: actionSize };
|
|
1207
|
+
const BackAction = getScrollViewConfig().BackAction ?? Appbar.BackAction;
|
|
1208
|
+
const backActionElement = typeof backAction === "function" ? /* @__PURE__ */ jsx10(BackAction, { accessibilityLabel: backActionAccessibilityLabel, onPress: backAction, size: iconSize ?? actionSize / 2, style: buttonStyle }) : backAction;
|
|
1200
1209
|
const actionShadow = { borderRadius: actionSize / 2, elevation: 2, shadowColor: "#000", shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.15, shadowRadius: 2 };
|
|
1201
1210
|
const leadingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", left: actionMargin, position: "absolute", top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
1202
1211
|
const trailingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", position: "absolute", right: actionMargin, top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
@@ -1216,10 +1225,10 @@ var ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, backActionAc
|
|
|
1216
1225
|
/* @__PURE__ */ jsx10(Animated6.View, { pointerEvents: "none", style: [styles7.progress, progressStyle], children: /* @__PURE__ */ jsx10(ProgressBar, { indeterminate: progress === null, visible: progressing, progress: progress ?? void 0 }) }),
|
|
1217
1226
|
backAction && (effectiveBackActionFixed ? /* @__PURE__ */ jsxs6(Animated6.View, { style: leadingStyle, children: [
|
|
1218
1227
|
/* @__PURE__ */ jsx10(ActionBg, { blur, style: actionStyle }),
|
|
1219
|
-
|
|
1228
|
+
backActionElement
|
|
1220
1229
|
] }) : /* @__PURE__ */ jsxs6(Animated6.View, { style: [leadingStyle, translateStyle], children: [
|
|
1221
1230
|
/* @__PURE__ */ jsx10(ActionBg, { blur, style: actionStyle }),
|
|
1222
|
-
|
|
1231
|
+
backActionElement
|
|
1223
1232
|
] })),
|
|
1224
1233
|
trailingAction && (trailingActionFixed ? /* @__PURE__ */ jsxs6(View6, { style: trailingStyle, children: [
|
|
1225
1234
|
/* @__PURE__ */ jsx10(ActionBg, { blur, style: actionStyle }),
|
|
@@ -1686,6 +1695,7 @@ export {
|
|
|
1686
1695
|
PullSearch,
|
|
1687
1696
|
ScrollView,
|
|
1688
1697
|
ScrollViewChromeProvider,
|
|
1698
|
+
ScrollViewConfigProvider,
|
|
1689
1699
|
ScrollViewContext,
|
|
1690
1700
|
ScrollViewFooter,
|
|
1691
1701
|
ScrollViewHeader,
|
|
@@ -1693,7 +1703,9 @@ export {
|
|
|
1693
1703
|
ScrollViewSettingsContext,
|
|
1694
1704
|
ScrollViewSettingsProvider,
|
|
1695
1705
|
SectionList,
|
|
1706
|
+
configureScrollView,
|
|
1696
1707
|
defaultScrollViewSettings,
|
|
1708
|
+
getScrollViewConfig,
|
|
1697
1709
|
scrollViewActions,
|
|
1698
1710
|
scrollViewReducer,
|
|
1699
1711
|
useKeyboardInset,
|
package/package.json
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { createModuleConfig } from '@rific/core'
|
|
2
|
+
import type { ComponentType, ReactNode } from 'react'
|
|
3
|
+
import type { ViewStyle } from 'react-native'
|
|
4
|
+
|
|
5
|
+
// What ScrollViewHeader passes the back action it renders for a plain `backAction` callback.
|
|
6
|
+
// react-native-paper's Appbar.BackAction (the default) takes these, and so does
|
|
7
|
+
// @rific/feedback-press's AppbarBackAction, which wraps it, so either drops in as is.
|
|
8
|
+
export type ScrollViewBackActionProps = {
|
|
9
|
+
accessibilityLabel?: string
|
|
10
|
+
onPress: () => void
|
|
11
|
+
size: number
|
|
12
|
+
style: ViewStyle
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export type ScrollViewConfig = {
|
|
16
|
+
/** Component ScrollViewHeader renders when `backAction` is a plain callback. Pass `AppbarBackAction` from `@rific/feedback-press` to give every header's back button its haptics and sound; omit to keep react-native-paper's `Appbar.BackAction`. A `backAction` element on one header still replaces it there. */
|
|
17
|
+
BackAction?: ComponentType<ScrollViewBackActionProps>
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// @rific/core's createModuleConfig() supplies the module-level config singleton (configure/
|
|
21
|
+
// getConfig/Provider) every @rific package wires up the same way - see its own doc comment for
|
|
22
|
+
// why this is plain module state rather than React Context. It injects a component instead of
|
|
23
|
+
// depending on @rific/feedback-press, same as @rific/resizable-input's TextInputComponent.
|
|
24
|
+
//
|
|
25
|
+
// Not to be confused with ScrollViewProvider (per screen, scroll state) or
|
|
26
|
+
// ScrollViewSettingsProvider (app-wide, persisted user settings): this one is app-wide startup
|
|
27
|
+
// config, mounted once.
|
|
28
|
+
const scrollViewConfig = createModuleConfig<ScrollViewConfig>()
|
|
29
|
+
|
|
30
|
+
export const configureScrollView = scrollViewConfig.configure
|
|
31
|
+
export const getScrollViewConfig = scrollViewConfig.getConfig
|
|
32
|
+
export const ScrollViewConfigProvider = scrollViewConfig.Provider
|
|
33
|
+
|
|
34
|
+
export type ScrollViewConfigProviderProps = ScrollViewConfig & { children: ReactNode }
|
package/src/ScrollViewHeader.tsx
CHANGED
|
@@ -5,13 +5,15 @@ import { Appbar, ProgressBar, Surface, useTheme } from 'react-native-paper'
|
|
|
5
5
|
import Animated, { useAnimatedStyle, useSharedValue } from 'react-native-reanimated'
|
|
6
6
|
import { useSafeAreaInsets } from 'react-native-safe-area-context'
|
|
7
7
|
|
|
8
|
+
import { getScrollViewConfig } from './ScrollViewConfig'
|
|
8
9
|
import { ScrollViewContext } from './ScrollViewContext'
|
|
9
10
|
import { ScrollViewSettingsContext } from './ScrollViewSettingsContext'
|
|
10
11
|
|
|
11
12
|
export type ScrollViewHeaderProps = {
|
|
12
13
|
actionSize?: number
|
|
13
14
|
actionStyle?: ViewStyle
|
|
14
|
-
// A plain callback renders the default Appbar.BackAction
|
|
15
|
+
// A plain callback renders the default back action (Paper's Appbar.BackAction unless the app set
|
|
16
|
+
// another with configureScrollView({ BackAction }), themed onSurface, sized/positioned by
|
|
15
17
|
// actionSize/iconSize below) - the common case, unchanged from before. Passing a ReactNode
|
|
16
18
|
// instead skips that default entirely and renders the given element in its place, same escape
|
|
17
19
|
// hatch trailingAction already gave the other corner: a caller that wants its own color, icon,
|
|
@@ -131,6 +133,10 @@ export const ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, bac
|
|
|
131
133
|
}, [headerFixed, headerHeightShared, top, headerOffset, pullSearchHeightShared, scrollPosition, snapBackHeaderShared])
|
|
132
134
|
const actionTop = top + actionMargin
|
|
133
135
|
const buttonStyle = { borderRadius: actionSize, height: actionSize, margin: 0, width: actionSize }
|
|
136
|
+
// A plain callback renders the configured BackAction (configureScrollView / ScrollViewConfigProvider),
|
|
137
|
+
// Paper's Appbar.BackAction by default. Read at render, like every createModuleConfig consumer.
|
|
138
|
+
const BackAction = getScrollViewConfig().BackAction ?? Appbar.BackAction
|
|
139
|
+
const backActionElement = typeof backAction === 'function' ? <BackAction accessibilityLabel={backActionAccessibilityLabel} onPress={backAction} size={iconSize ?? actionSize / 2} style={buttonStyle} /> : backAction
|
|
134
140
|
const actionShadow = { borderRadius: actionSize / 2, elevation: 2, shadowColor: '#000', shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.15, shadowRadius: 2 }
|
|
135
141
|
const leadingStyle = { alignItems: 'center' as const, height: actionSize, justifyContent: 'center' as const, left: actionMargin, position: 'absolute' as const, top: actionTop, width: actionSize, zIndex: 3, ...actionShadow }
|
|
136
142
|
const trailingStyle = { alignItems: 'center' as const, height: actionSize, justifyContent: 'center' as const, position: 'absolute' as const, right: actionMargin, top: actionTop, width: actionSize, zIndex: 3, ...actionShadow }
|
|
@@ -175,12 +181,12 @@ export const ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, bac
|
|
|
175
181
|
(effectiveBackActionFixed ? (
|
|
176
182
|
<Animated.View style={leadingStyle}>
|
|
177
183
|
<ActionBg blur={blur} style={actionStyle} />
|
|
178
|
-
{
|
|
184
|
+
{backActionElement}
|
|
179
185
|
</Animated.View>
|
|
180
186
|
) : (
|
|
181
187
|
<Animated.View style={[leadingStyle, translateStyle]}>
|
|
182
188
|
<ActionBg blur={blur} style={actionStyle} />
|
|
183
|
-
{
|
|
189
|
+
{backActionElement}
|
|
184
190
|
</Animated.View>
|
|
185
191
|
))}
|
|
186
192
|
{trailingAction &&
|
package/src/index.ts
CHANGED
|
@@ -10,6 +10,8 @@ export type { ScrollViewProps } from './ScrollView'
|
|
|
10
10
|
export { ScrollView } from './ScrollView'
|
|
11
11
|
export type { ScrollViewChromeProviderProps } from './ScrollViewChromeProvider'
|
|
12
12
|
export { ScrollViewChromeProvider } from './ScrollViewChromeProvider'
|
|
13
|
+
export type { ScrollViewBackActionProps, ScrollViewConfig, ScrollViewConfigProviderProps } from './ScrollViewConfig'
|
|
14
|
+
export { configureScrollView, getScrollViewConfig, ScrollViewConfigProvider } from './ScrollViewConfig'
|
|
13
15
|
export type { ScrollViewContextType } from './ScrollViewContext'
|
|
14
16
|
export { ScrollViewContext } from './ScrollViewContext'
|
|
15
17
|
export type { ScrollViewFooterProps } from './ScrollViewFooter'
|