expo-android-glass-view 0.1.0 → 0.1.2
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/CHANGELOG.md +12 -2
- package/README.md +83 -13
- package/android/src/main/java/expo/modules/androidglassview/ExpoAndroidGlassViewModule.kt +5 -0
- package/android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt +95 -27
- package/build/AndroidGlassBottomTabs.android.d.ts.map +1 -1
- package/build/AndroidGlassBottomTabs.android.js +11 -2
- package/build/AndroidGlassBottomTabs.android.js.map +1 -1
- package/build/AndroidGlassComponents.types.d.ts +5 -4
- package/build/AndroidGlassComponents.types.d.ts.map +1 -1
- package/build/AndroidGlassComponents.types.js.map +1 -1
- package/build/MinimizeOnScroll.d.ts +41 -0
- package/build/MinimizeOnScroll.d.ts.map +1 -0
- package/build/MinimizeOnScroll.js +76 -0
- package/build/MinimizeOnScroll.js.map +1 -0
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1 -1
- package/build/index.js.map +1 -1
- package/package.json +1 -1
- package/src/AndroidGlassBottomTabs.android.tsx +10 -2
- package/src/AndroidGlassComponents.types.ts +5 -4
- package/src/MinimizeOnScroll.tsx +98 -0
- package/src/index.ts +6 -1
- package/build/useMinimizeOnScroll.d.ts +0 -17
- package/build/useMinimizeOnScroll.d.ts.map +0 -1
- package/build/useMinimizeOnScroll.js +0 -39
- package/build/useMinimizeOnScroll.js.map +0 -1
- package/src/useMinimizeOnScroll.ts +0 -53
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.2 — 2026-09-10
|
|
4
|
+
|
|
5
|
+
- Fix a crash when a glass view sits inside a react-native-screens stack (Expo Router and React
|
|
6
|
+
Navigation native stacks): `IllegalStateException: Recording currently in progress`. While a
|
|
7
|
+
glass view captures its backdrop, its ancestors are still being drawn; the capture no longer
|
|
8
|
+
calls their `draw()` again but draws their background and children itself.
|
|
9
|
+
- New native constant `captureRevision` (2), so JS can tell a fixed binary from an older one.
|
|
10
|
+
|
|
3
11
|
## 0.1.0 — 2026-09-10
|
|
4
12
|
|
|
5
13
|
First release.
|
|
@@ -8,6 +16,8 @@ First release.
|
|
|
8
16
|
whose backdrop is the live React Native screen behind it.
|
|
9
17
|
- `AndroidGlassButton`, `AndroidGlassToggle`, `AndroidGlassSlider`, `AndroidGlassBottomTabs` and
|
|
10
18
|
`AndroidGlassTab`: Kyant's Backdrop Catalog components, driven from React Native.
|
|
11
|
-
-
|
|
12
|
-
|
|
19
|
+
- Minimize on scroll: the tab bar shrinks while a list scrolls down and comes back on scroll up or
|
|
20
|
+
touch, like iOS 26. Animated natively. `MinimizeOnScrollProvider` + `useMinimizeOnScrollHandler`
|
|
21
|
+
share it across a navigator's screens; `useMinimizeOnScroll` and the `minimized` prop cover a
|
|
22
|
+
single component.
|
|
13
23
|
- iOS and web: plain fallbacks with the same API.
|
package/README.md
CHANGED
|
@@ -19,6 +19,8 @@ import {
|
|
|
19
19
|
AndroidGlassSlider,
|
|
20
20
|
AndroidGlassBottomTabs,
|
|
21
21
|
AndroidGlassTab,
|
|
22
|
+
MinimizeOnScrollProvider,
|
|
23
|
+
useMinimizeOnScrollHandler,
|
|
22
24
|
useMinimizeOnScroll,
|
|
23
25
|
} from 'expo-android-glass-view';
|
|
24
26
|
```
|
|
@@ -184,27 +186,95 @@ droplet returns to `selectedIndex`.
|
|
|
184
186
|
|
|
185
187
|
Like iOS 26 tab bars, the bar can shrink while the user scrolls down a list, and come back when
|
|
186
188
|
they scroll up, get back to the top or touch it. It gets shorter and narrower; every tab keeps its
|
|
187
|
-
first child (the icon) while the rest (the label) fades out.
|
|
188
|
-
|
|
189
|
+
first child (the icon) while the rest (the label) fades out.
|
|
190
|
+
|
|
191
|
+
Wrap the bar and the screens in `MinimizeOnScrollProvider`, and give each list the handler from
|
|
192
|
+
`useMinimizeOnScrollHandler`:
|
|
193
|
+
|
|
194
|
+
```tsx
|
|
195
|
+
<MinimizeOnScrollProvider>
|
|
196
|
+
{/* your navigator, or screens + AndroidGlassBottomTabs */}
|
|
197
|
+
</MinimizeOnScrollProvider>
|
|
198
|
+
|
|
199
|
+
// In any screen:
|
|
200
|
+
const onScroll = useMinimizeOnScrollHandler();
|
|
201
|
+
<FlatList onScroll={onScroll} scrollEventThrottle={16} … />
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
Inside the provider, `AndroidGlassBottomTabs` follows the shared state by itself (unless you pass
|
|
205
|
+
`minimized`). Each list tracks its own scroll position, and a screen isn't re-rendered when the
|
|
206
|
+
bar minimizes. The scroll position is read in JS, where the list lives; only the resulting flag
|
|
207
|
+
goes to the native side, where the animation runs. Any list that reports `onScroll` works
|
|
208
|
+
(ScrollView, FlatList, SectionList, FlashList…); if you already have an `onScroll`, call the
|
|
209
|
+
handler from it.
|
|
210
|
+
|
|
211
|
+
When the list and the bar are in the same component, `useMinimizeOnScroll` alone is enough:
|
|
189
212
|
|
|
190
213
|
```tsx
|
|
191
214
|
const { minimized, setMinimized, onScroll } = useMinimizeOnScroll();
|
|
192
215
|
|
|
193
216
|
<ScrollView onScroll={onScroll} scrollEventThrottle={16}>…</ScrollView>
|
|
217
|
+
<AndroidGlassBottomTabs minimized={minimized} onMinimizedChange={setMinimized} …>…</AndroidGlassBottomTabs>
|
|
218
|
+
```
|
|
194
219
|
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
220
|
+
The iOS and web fallbacks don't minimize; there, `useMinimizeOnScrollHandler` returns `undefined`.
|
|
221
|
+
|
|
222
|
+
### With Expo Router or React Navigation
|
|
223
|
+
|
|
224
|
+
The bar doesn't navigate by itself: use it as the navigator's `tabBar`, driven by the navigation
|
|
225
|
+
state. Tap vetoes (`tabPress` with `preventDefault`) send the droplet back.
|
|
226
|
+
|
|
227
|
+
```tsx
|
|
228
|
+
import { Tabs } from 'expo-router';
|
|
229
|
+
import type { BottomTabBarProps } from 'expo-router/js-tabs';
|
|
230
|
+
import { StyleSheet } from 'react-native';
|
|
231
|
+
import {
|
|
232
|
+
AndroidGlassBottomTabs,
|
|
233
|
+
AndroidGlassTab,
|
|
234
|
+
MinimizeOnScrollProvider,
|
|
235
|
+
} from 'expo-android-glass-view';
|
|
236
|
+
|
|
237
|
+
function GlassTabBar({ state, descriptors, navigation }: BottomTabBarProps) {
|
|
238
|
+
// Routes hidden with `href: null` reach a custom bar as `display: 'none'`.
|
|
239
|
+
const routes = state.routes.filter(
|
|
240
|
+
(route) => StyleSheet.flatten(descriptors[route.key].options.tabBarItemStyle)?.display !== 'none'
|
|
241
|
+
);
|
|
242
|
+
const focusedKey = state.routes[state.index].key;
|
|
243
|
+
return (
|
|
244
|
+
<AndroidGlassBottomTabs
|
|
245
|
+
selectedIndex={routes.findIndex((route) => route.key === focusedKey)}
|
|
246
|
+
onTabSelected={(index) => {
|
|
247
|
+
const route = routes[index];
|
|
248
|
+
const event = navigation.emit({ type: 'tabPress', target: route.key, canPreventDefault: true });
|
|
249
|
+
if (!event.defaultPrevented) navigation.navigate(route.name, route.params);
|
|
250
|
+
}}
|
|
251
|
+
style={{ position: 'absolute', left: 24, right: 24, bottom: 32 }}>
|
|
252
|
+
{routes.map((route) => {
|
|
253
|
+
const { options } = descriptors[route.key];
|
|
254
|
+
return (
|
|
255
|
+
<AndroidGlassTab
|
|
256
|
+
key={route.key}
|
|
257
|
+
label={options.title ?? route.name}
|
|
258
|
+
// The droplet tints the selected tab, so draw icons in one neutral colour.
|
|
259
|
+
icon={options.tabBarIcon?.({ focused: false, color: '#000000', size: 24 })}
|
|
260
|
+
/>
|
|
261
|
+
);
|
|
262
|
+
})}
|
|
263
|
+
</AndroidGlassBottomTabs>
|
|
264
|
+
);
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
export default function TabLayout() {
|
|
268
|
+
return (
|
|
269
|
+
<MinimizeOnScrollProvider>
|
|
270
|
+
<Tabs tabBar={(props) => <GlassTabBar {...props} />} />
|
|
271
|
+
</MinimizeOnScrollProvider>
|
|
272
|
+
);
|
|
273
|
+
}
|
|
202
274
|
```
|
|
203
275
|
|
|
204
|
-
The
|
|
205
|
-
|
|
206
|
-
SectionList, FlashList…); if you already have an `onScroll`, call the hook's from it. The iOS and
|
|
207
|
-
web fallbacks don't minimize.
|
|
276
|
+
The bar floats over the screens, so give their content some bottom padding. With React
|
|
277
|
+
Navigation, the same component works as `createBottomTabNavigator`'s `tabBar`.
|
|
208
278
|
|
|
209
279
|
## Colours and dark mode
|
|
210
280
|
|
|
@@ -10,6 +10,11 @@ class ExpoAndroidGlassViewModule : Module() {
|
|
|
10
10
|
override fun definition() = ModuleDefinition {
|
|
11
11
|
Name("ExpoAndroidGlassView")
|
|
12
12
|
|
|
13
|
+
// Bumped when the backdrop capture changes in a way JS may need to know about.
|
|
14
|
+
// 2: ancestors of a sampling glass view are never drawn again through their own draw()
|
|
15
|
+
// (0.1.1 crashed inside react-native-screens stacks).
|
|
16
|
+
Constant("captureRevision") { 2 }
|
|
17
|
+
|
|
13
18
|
View(AndroidGlassView::class) {
|
|
14
19
|
Name("AndroidGlassView")
|
|
15
20
|
|
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
*
|
|
6
6
|
* Changes from upstream: renamed, comments translated, generalised from "skip the one glass
|
|
7
7
|
* that is sampling" to "skip every other glass view", glass ancestors of the sampling view are
|
|
8
|
-
* drawn instead of skipped,
|
|
9
|
-
* transform (left/top, scroll, matrix, alpha) instead of screen deltas
|
|
8
|
+
* drawn instead of skipped, expanded branches are positioned with the framework's own child
|
|
9
|
+
* transform (left/top, scroll, matrix, alpha) instead of screen deltas, and the ancestors of the
|
|
10
|
+
* sampling view are drawn child by child instead of through their own draw().
|
|
10
11
|
*/
|
|
11
12
|
package expo.modules.androidglassview.capture
|
|
12
13
|
|
|
@@ -21,33 +22,44 @@ import androidx.annotation.RequiresApi
|
|
|
21
22
|
*
|
|
22
23
|
* A plain `source.draw(canvas)` is only safe when no glass view lives under `source`:
|
|
23
24
|
*
|
|
24
|
-
* 1. **Re-entrant
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
* `
|
|
25
|
+
* 1. **Re-entrant drawing.** A glass view samples while it is being drawn, so its ancestors are in
|
|
26
|
+
* the middle of their own draw: their RenderNodes are recording and their `dispatchDraw` is
|
|
27
|
+
* mid-loop. Drawing one of them again re-enters both. The child on the way to the glass goes
|
|
28
|
+
* back through `drawChild` → `updateDisplayListIfDirty` and throws
|
|
29
|
+
* `IllegalStateException: Recording currently in progress` — hiding it doesn't help, a view
|
|
30
|
+
* with a running view Animation (react-native-screens' screen transitions) is drawn even when
|
|
31
|
+
* invisible. Per-view drawing state breaks as well: ViewGroup reuses one pre-sorted child list
|
|
32
|
+
* (children with elevation) that the inner call clears under the outer loop.
|
|
28
33
|
* 2. **Reference cycles.** `drawChild` records a *reference* to a child's RenderNode, not pixels.
|
|
29
34
|
* If that subtree contains the sampling glass, the glass would draw itself (glass → backdrop →
|
|
30
35
|
* ancestor → glass), which recurses forever on the RenderThread. The same happens between two
|
|
31
36
|
* glass views that sample each other.
|
|
32
37
|
*
|
|
33
|
-
* So
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
38
|
+
* So the ancestors of the sampling glass are never drawn through their own `draw()`: their
|
|
39
|
+
* background and children are drawn here, in their drawing order ([drawAncestor]) — other glass
|
|
40
|
+
* views left out, containers of glass one level deeper, every other child with its public
|
|
41
|
+
* [View.draw] (its own content is copied, its subtree still goes through RenderNode references).
|
|
42
|
+
*
|
|
43
|
+
* Every other container that has a skipped glass view somewhere below it (an *expanded*
|
|
44
|
+
* container) is not being drawn right now, so it is drawn with the public [View.draw], which
|
|
45
|
+
* neither touches its RenderNode nor records a reference to it. For that call, its children that
|
|
46
|
+
* are skipped glass views or contain one are hidden (so `dispatchDraw` skips them); the ones that
|
|
47
|
+
* only contain glass are then drawn one level deeper with the same rule. Every other child keeps
|
|
48
|
+
* going through the normal fast path (a RenderNode reference). That is safe: nothing inside those
|
|
49
|
+
* subtrees is ever hidden, so a display list that happens to be re-recorded here is exactly what
|
|
50
|
+
* the regular frame would record, and it cannot reference a skipped glass view. It also keeps the
|
|
51
|
+
* backdrop live for free — when such a child re-records its display list or animates its
|
|
52
|
+
* RenderNode properties, the backdrop sees it.
|
|
42
53
|
*
|
|
43
54
|
* Glass views that are *ancestors* of the sampling one are not skipped: glass on top of a glass
|
|
44
55
|
* card sees the card. That cannot form a cycle, because an ancestor never samples its own subtree.
|
|
45
56
|
*
|
|
46
|
-
* Known trade-offs
|
|
47
|
-
*
|
|
48
|
-
*
|
|
57
|
+
* Known trade-offs: the children of ancestors are drawn without their view Animation and
|
|
58
|
+
* elevation shadow; inside an expanded container that is not an ancestor, glass-containing
|
|
59
|
+
* branches are drawn after their siblings, so a sibling that normally paints above such a branch
|
|
60
|
+
* ends up below it in the backdrop.
|
|
49
61
|
*/
|
|
50
|
-
@RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility
|
|
62
|
+
@RequiresApi(Build.VERSION_CODES.Q) // View.setTransitionVisibility, ViewGroup.getChildDrawingOrder(int)
|
|
51
63
|
internal class ViewBackdropCapture {
|
|
52
64
|
|
|
53
65
|
/** Containers that have at least one skipped glass view somewhere below them. */
|
|
@@ -56,7 +68,7 @@ internal class ViewBackdropCapture {
|
|
|
56
68
|
/** Glass views that are never drawn into this backdrop. */
|
|
57
69
|
private val excluded = HashSet<View>()
|
|
58
70
|
|
|
59
|
-
/** Ancestors of the sampling glass view, up to the source. */
|
|
71
|
+
/** Ancestors of the sampling glass view, up to the source. They are being drawn right now. */
|
|
60
72
|
private val selfPath = HashSet<View>()
|
|
61
73
|
|
|
62
74
|
private val path = ArrayList<View>()
|
|
@@ -114,6 +126,11 @@ internal class ViewBackdropCapture {
|
|
|
114
126
|
}
|
|
115
127
|
|
|
116
128
|
private fun drawLevel(canvas: Canvas, host: View) {
|
|
129
|
+
if (host is ViewGroup && host in selfPath) {
|
|
130
|
+
drawAncestor(canvas, host)
|
|
131
|
+
return
|
|
132
|
+
}
|
|
133
|
+
|
|
117
134
|
val group = if (host in expanded) host as? ViewGroup else null
|
|
118
135
|
val firstHidden = hidden.size
|
|
119
136
|
if (group != null) {
|
|
@@ -149,13 +166,7 @@ internal class ViewBackdropCapture {
|
|
|
149
166
|
val childSave = canvas.save()
|
|
150
167
|
// Same transform the parent applies when it draws the child normally.
|
|
151
168
|
canvas.translate((child.left - host.scrollX).toFloat(), (child.top - host.scrollY).toFloat())
|
|
152
|
-
|
|
153
|
-
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
154
|
-
if (clipChildren) canvas.clipRect(0f, 0f, child.width.toFloat(), child.height.toFloat())
|
|
155
|
-
val alpha = child.alpha
|
|
156
|
-
if (alpha < 1f) {
|
|
157
|
-
canvas.saveLayerAlpha(0f, 0f, child.width.toFloat(), child.height.toFloat(), (alpha * 255f).toInt())
|
|
158
|
-
}
|
|
169
|
+
applyChildTransform(canvas, child, clipChildren)
|
|
159
170
|
drawLevel(canvas, child)
|
|
160
171
|
canvas.restoreToCount(childSave)
|
|
161
172
|
}
|
|
@@ -166,6 +177,63 @@ internal class ViewBackdropCapture {
|
|
|
166
177
|
}
|
|
167
178
|
}
|
|
168
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Draws an ancestor of the sampling glass view without calling its draw() (see the class
|
|
182
|
+
* comment): its background, then its children in drawing order.
|
|
183
|
+
*/
|
|
184
|
+
private fun drawAncestor(canvas: Canvas, host: ViewGroup) {
|
|
185
|
+
val save = canvas.save()
|
|
186
|
+
try {
|
|
187
|
+
// View.draw() paints the background at the view's origin, whatever its scroll offset.
|
|
188
|
+
host.background?.draw(canvas)
|
|
189
|
+
canvas.translate(-host.scrollX.toFloat(), -host.scrollY.toFloat())
|
|
190
|
+
val clipChildren = host.clipChildren
|
|
191
|
+
for (child in childrenInDrawingOrder(host)) {
|
|
192
|
+
if (child in excluded) continue
|
|
193
|
+
// Same visibility rule as ViewGroup.dispatchDraw.
|
|
194
|
+
if (child.visibility != View.VISIBLE && child.animation == null) continue
|
|
195
|
+
val childSave = canvas.save()
|
|
196
|
+
canvas.translate(child.left.toFloat(), child.top.toFloat())
|
|
197
|
+
applyChildTransform(canvas, child, clipChildren)
|
|
198
|
+
if (child in expanded) {
|
|
199
|
+
drawLevel(canvas, child)
|
|
200
|
+
} else {
|
|
201
|
+
canvas.translate(-child.scrollX.toFloat(), -child.scrollY.toFloat())
|
|
202
|
+
child.draw(canvas)
|
|
203
|
+
}
|
|
204
|
+
canvas.restoreToCount(childSave)
|
|
205
|
+
}
|
|
206
|
+
} finally {
|
|
207
|
+
canvas.restoreToCount(save)
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** The child's matrix, clip and alpha, as its parent applies them; the canvas is at its left/top. */
|
|
212
|
+
private fun applyChildTransform(canvas: Canvas, child: View, clipChildren: Boolean) {
|
|
213
|
+
val matrix = child.matrix
|
|
214
|
+
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
215
|
+
if (clipChildren) canvas.clipRect(0f, 0f, child.width.toFloat(), child.height.toFloat())
|
|
216
|
+
val alpha = child.alpha
|
|
217
|
+
if (alpha < 1f) {
|
|
218
|
+
canvas.saveLayerAlpha(0f, 0f, child.width.toFloat(), child.height.toFloat(), (alpha * 255f).toInt())
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* The children in the order their parent draws them, like ViewGroup.buildOrderedChildList: the
|
|
224
|
+
* custom drawing order (React Native's zIndex), then elevation, stable.
|
|
225
|
+
*/
|
|
226
|
+
private fun childrenInDrawingOrder(group: ViewGroup): List<View> {
|
|
227
|
+
val count = group.childCount
|
|
228
|
+
val children = ArrayList<View>(count)
|
|
229
|
+
for (i in 0 until count) {
|
|
230
|
+
val index = group.getChildDrawingOrder(i)
|
|
231
|
+
children.add(group.getChildAt(if (index in 0 until count) index else i))
|
|
232
|
+
}
|
|
233
|
+
children.sortBy { it.z }
|
|
234
|
+
return children
|
|
235
|
+
}
|
|
236
|
+
|
|
169
237
|
companion object {
|
|
170
238
|
private var depth = 0
|
|
171
239
|
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AndroidGlassBottomTabs.android.d.ts","sourceRoot":"","sources":["../src/AndroidGlassBottomTabs.android.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;
|
|
1
|
+
{"version":3,"file":"AndroidGlassBottomTabs.android.d.ts","sourceRoot":"","sources":["../src/AndroidGlassBottomTabs.android.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,gCAAgC,CAAC;AAuBlF,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,EAC7C,aAAa,EACb,aAAa,EACb,SAAS,EACT,iBAAiB,EACjB,WAAW,EACX,cAAc,EACd,QAAQ,EACR,KAAK,EACL,GAAG,IAAI,EACR,EAAE,2BAA2B,qBAgD7B"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { requireNativeView } from 'expo';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { StyleSheet, View } from 'react-native';
|
|
4
|
+
import { MinimizedStateContext } from './MinimizeOnScroll';
|
|
4
5
|
import { toNativeColor } from './utils';
|
|
5
6
|
const NativeAndroidGlassBottomTabs = requireNativeView('ExpoAndroidGlassView', 'AndroidGlassBottomTabs');
|
|
6
7
|
export default function AndroidGlassBottomTabs({ selectedIndex, onTabSelected, minimized, onMinimizedChange, accentColor, containerColor, children, style, ...rest }) {
|
|
@@ -11,12 +12,20 @@ export default function AndroidGlassBottomTabs({ selectedIndex, onTabSelected, m
|
|
|
11
12
|
// up with earlier selections) from a current one.
|
|
12
13
|
const [eventCount, setEventCount] = React.useState(0);
|
|
13
14
|
const selected = selectedIndex ?? ownIndex;
|
|
14
|
-
|
|
15
|
+
// Inside a MinimizeOnScrollProvider, the bar follows the shared state unless `minimized` is given.
|
|
16
|
+
const shared = React.useContext(MinimizedStateContext);
|
|
17
|
+
const followsProvider = minimized === undefined;
|
|
18
|
+
return (<NativeAndroidGlassBottomTabs accessibilityRole="tablist" {...rest} style={[styles.bar, style]} selectedIndex={selected} tabsCount={tabs.length} mostRecentEventCount={eventCount} minimized={minimized ?? shared?.minimized ?? false} accentColor={toNativeColor(accentColor)} containerColor={toNativeColor(containerColor)} onTabSelected={(event) => {
|
|
15
19
|
const { index, eventCount: count } = event.nativeEvent;
|
|
16
20
|
setEventCount((current) => Math.max(current, count));
|
|
17
21
|
setOwnIndex(index);
|
|
18
22
|
onTabSelected?.(index);
|
|
19
|
-
}} onMinimizedChange={(event) =>
|
|
23
|
+
}} onMinimizedChange={(event) => {
|
|
24
|
+
const value = event.nativeEvent.minimized;
|
|
25
|
+
if (followsProvider)
|
|
26
|
+
shared?.setMinimized(value);
|
|
27
|
+
onMinimizedChange?.(value);
|
|
28
|
+
}}>
|
|
20
29
|
{tabs.map((tab, index) => (
|
|
21
30
|
// The native bar handles taps and drags, and draws these views itself (inside the glass
|
|
22
31
|
// and, tinted, under the droplet), so they must stay real views and not take touches.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AndroidGlassBottomTabs.android.js","sourceRoot":"","sources":["../src/AndroidGlassBottomTabs.android.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAC;AACzC,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGh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AC,CAChC,CAAC;AACJ,CAAC;AAED,MAAM,MAAM,GAAG,UAAU,CAAC,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,GAAG,EAAE;QACH,MAAM,EAAE,EAAE;QACV,aAAa,EAAE,KAAK;QACpB,iBAAiB,EAAE,CAAC;KACrB;IACD,GAAG,EAAE;QACH,IAAI,EAAE,CAAC;QACP,UAAU,EAAE,QAAQ;QACpB,cAAc,EAAE,QAAQ;QACxB,GAAG,EAAE,CAAC;KACP;CACF,CAAC,CAAC","sourcesContent":["import { requireNativeView } from 'expo';\nimport * as React from 'react';\nimport { StyleSheet, View } from 'react-native';\n\nimport type { AndroidGlassBottomTabsProps } from './AndroidGlassComponents.types';\nimport { MinimizedStateContext } from './MinimizeOnScroll';\nimport { type NativeColor, toNativeColor } from './utils';\n\ntype IndexEvent = { nativeEvent: { index: number; eventCount: number } };\ntype MinimizedEvent = { nativeEvent: { minimized: boolean } };\n\ntype NativeAndroidGlassBottomTabsProps = Omit<\n AndroidGlassBottomTabsProps,\n 'onTabSelected' | 'onMinimizedChange' | 'accentColor' | 'containerColor'\n> & {\n tabsCount: number;\n /** Count of the last selection event handled here (see ControlledProp on the native side). */\n mostRecentEventCount: number;\n onTabSelected: (event: IndexEvent) => void;\n onMinimizedChange: (event: MinimizedEvent) => void;\n accentColor?: NativeColor;\n containerColor?: NativeColor;\n};\n\nconst NativeAndroidGlassBottomTabs: React.ComponentType<NativeAndroidGlassBottomTabsProps> =\n requireNativeView('ExpoAndroidGlassView', 'AndroidGlassBottomTabs');\n\nexport default function AndroidGlassBottomTabs({\n selectedIndex,\n onTabSelected,\n minimized,\n onMinimizedChange,\n accentColor,\n containerColor,\n children,\n style,\n ...rest\n}: AndroidGlassBottomTabsProps) {\n const tabs = React.Children.toArray(children).filter(React.isValidElement);\n // Without a `selectedIndex` prop, the bar keeps the user's selection.\n const [ownIndex, setOwnIndex] = React.useState(0);\n // Sent back with `selectedIndex`, so the native side can tell a stale index (JS still catching\n // up with earlier selections) from a current one.\n const [eventCount, setEventCount] = React.useState(0);\n const selected = selectedIndex ?? ownIndex;\n // Inside a MinimizeOnScrollProvider, the bar follows the shared state unless `minimized` is given.\n const shared = React.useContext(MinimizedStateContext);\n const followsProvider = minimized === undefined;\n return (\n <NativeAndroidGlassBottomTabs\n accessibilityRole=\"tablist\"\n {...rest}\n style={[styles.bar, style]}\n selectedIndex={selected}\n tabsCount={tabs.length}\n mostRecentEventCount={eventCount}\n minimized={minimized ?? shared?.minimized ?? false}\n accentColor={toNativeColor(accentColor)}\n containerColor={toNativeColor(containerColor)}\n onTabSelected={(event) => {\n const { index, eventCount: count } = event.nativeEvent;\n setEventCount((current) => Math.max(current, count));\n setOwnIndex(index);\n onTabSelected?.(index);\n }}\n onMinimizedChange={(event) => {\n const value = event.nativeEvent.minimized;\n if (followsProvider) shared?.setMinimized(value);\n onMinimizedChange?.(value);\n }}>\n {tabs.map((tab, index) => (\n // The native bar handles taps and drags, and draws these views itself (inside the glass\n // and, tinted, under the droplet), so they must stay real views and not take touches.\n <View\n key={tab.key ?? index}\n collapsable={false}\n pointerEvents=\"none\"\n accessibilityRole=\"tab\"\n accessibilityState={{ selected: index === selected }}\n style={styles.tab}>\n {tab}\n </View>\n ))}\n </NativeAndroidGlassBottomTabs>\n );\n}\n\nconst styles = StyleSheet.create({\n // 4 dp side padding keeps the tabs aligned with the droplet: (width - 8 dp) / count each.\n bar: {\n height: 64,\n flexDirection: 'row',\n paddingHorizontal: 4,\n },\n tab: {\n flex: 1,\n alignItems: 'center',\n justifyContent: 'center',\n gap: 2,\n },\n});\n"]}
|
|
@@ -47,13 +47,14 @@ export type AndroidGlassBottomTabsProps = ViewProps & {
|
|
|
47
47
|
onTabSelected?: (index: number) => void;
|
|
48
48
|
/**
|
|
49
49
|
* Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps
|
|
50
|
-
* only its first child (the icon) and the rest (the label) fades out. Animated natively
|
|
51
|
-
*
|
|
50
|
+
* only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a
|
|
51
|
+
* `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.
|
|
52
52
|
*/
|
|
53
53
|
minimized?: boolean;
|
|
54
54
|
/**
|
|
55
|
-
* Called with `false` when the user expands the minimized bar by touching it.
|
|
56
|
-
* `
|
|
55
|
+
* Called with `false` when the user expands the minimized bar by touching it. With
|
|
56
|
+
* `useMinimizeOnScroll`, pass its `setMinimized`; inside a `MinimizeOnScrollProvider` it isn't
|
|
57
|
+
* needed.
|
|
57
58
|
*/
|
|
58
59
|
onMinimizedChange?: (minimized: boolean) => void;
|
|
59
60
|
/** Colour the selected tab's content takes under the droplet. Default system blue. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AndroidGlassComponents.types.d.ts","sourceRoot":"","sources":["../src/AndroidGlassComponents.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AACvC,OAAO,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAEhF,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAEtE;;;;GAIG;AACH,MAAM,MAAM,uBAAuB,GAAG,qBAAqB,GAAG;IAC5D,wCAAwC;IACxC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,uDAAuD;IACvD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAClC;;;OAGG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG;IAChD,KAAK,CAAC,EAAE,OAAO,CAAC;IAChB,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACzC,+CAA+C;IAC/C,WAAW,CAAC,EAAE,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5B,wEAAwE;IACxE,QAAQ,CAAC,EAAE,SAAS,CAAC;CACtB,CAAC;AAEF,MAAM,MAAM,oBAAoB,GAAG;IACjC,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,UAAU,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CACnC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AndroidGlassComponents.types.js","sourceRoot":"","sources":["../src/AndroidGlassComponents.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactNode } from 'react';\nimport type { ColorValue, StyleProp, TextStyle, ViewProps } from 'react-native';\n\nimport type { AndroidGlassViewProps } from './AndroidGlassView.types';\n\n/**\n * Accepts every `AndroidGlassView` glass prop. `cornerRadius` defaults to a capsule.\n * Children (label, icon, …) are drawn inside the glass and follow its press deformation; they\n * are decorative, so don't put interactive elements in a button.\n */\nexport type AndroidGlassButtonProps = AndroidGlassViewProps & {\n /** Called when the button is tapped. */\n onPress?: () => void;\n /** Convenience label, rendered before the children. */\n title?: string;\n titleStyle?: StyleProp<TextStyle>;\n /**\n * Press and drag feedback: the glass stretches towards the finger and a highlight follows it.\n * Default true.\n */\n interactive?: boolean;\n};\n\nexport type AndroidGlassToggleProps = ViewProps & {\n value?: boolean;\n onValueChange?: (value: boolean) => void;\n /** Track colour when on. Default iOS green. */\n accentColor?: ColorValue;\n /** Track colour when off. */\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassSliderProps = ViewProps & {\n value?: number;\n /** Default 0. */\n minimumValue?: number;\n /** Default 1. */\n maximumValue?: number;\n /** Called continuously while the thumb is dragged. */\n onValueChange?: (value: number) => void;\n /** Called once when the finger is lifted, or after a tap on the track. */\n onSlidingComplete?: (value: number) => void;\n /** Colour of the filled part of the track. Default system blue. */\n accentColor?: ColorValue;\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassBottomTabsProps = ViewProps & {\n /** Index of the selected tab. */\n selectedIndex?: number;\n /** Called when the user taps a tab or drops the droplet on one. */\n onTabSelected?: (index: number) => void;\n /**\n * Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps\n * only its first child (the icon) and the rest (the label) fades out. Animated natively
|
|
1
|
+
{"version":3,"file":"AndroidGlassComponents.types.js","sourceRoot":"","sources":["../src/AndroidGlassComponents.types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ReactNode } from 'react';\nimport type { ColorValue, StyleProp, TextStyle, ViewProps } from 'react-native';\n\nimport type { AndroidGlassViewProps } from './AndroidGlassView.types';\n\n/**\n * Accepts every `AndroidGlassView` glass prop. `cornerRadius` defaults to a capsule.\n * Children (label, icon, …) are drawn inside the glass and follow its press deformation; they\n * are decorative, so don't put interactive elements in a button.\n */\nexport type AndroidGlassButtonProps = AndroidGlassViewProps & {\n /** Called when the button is tapped. */\n onPress?: () => void;\n /** Convenience label, rendered before the children. */\n title?: string;\n titleStyle?: StyleProp<TextStyle>;\n /**\n * Press and drag feedback: the glass stretches towards the finger and a highlight follows it.\n * Default true.\n */\n interactive?: boolean;\n};\n\nexport type AndroidGlassToggleProps = ViewProps & {\n value?: boolean;\n onValueChange?: (value: boolean) => void;\n /** Track colour when on. Default iOS green. */\n accentColor?: ColorValue;\n /** Track colour when off. */\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassSliderProps = ViewProps & {\n value?: number;\n /** Default 0. */\n minimumValue?: number;\n /** Default 1. */\n maximumValue?: number;\n /** Called continuously while the thumb is dragged. */\n onValueChange?: (value: number) => void;\n /** Called once when the finger is lifted, or after a tap on the track. */\n onSlidingComplete?: (value: number) => void;\n /** Colour of the filled part of the track. Default system blue. */\n accentColor?: ColorValue;\n trackColor?: ColorValue;\n};\n\nexport type AndroidGlassBottomTabsProps = ViewProps & {\n /** Index of the selected tab. */\n selectedIndex?: number;\n /** Called when the user taps a tab or drops the droplet on one. */\n onTabSelected?: (index: number) => void;\n /**\n * Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps\n * only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a\n * `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.\n */\n minimized?: boolean;\n /**\n * Called with `false` when the user expands the minimized bar by touching it. With\n * `useMinimizeOnScroll`, pass its `setMinimized`; inside a `MinimizeOnScrollProvider` it isn't\n * needed.\n */\n onMinimizedChange?: (minimized: boolean) => void;\n /** Colour the selected tab's content takes under the droplet. Default system blue. */\n accentColor?: ColorValue;\n /** Colour of the glass bar. */\n containerColor?: ColorValue;\n /** One child per tab, e.g. `AndroidGlassTab`. Tabs get equal widths. */\n children?: ReactNode;\n};\n\nexport type AndroidGlassTabProps = {\n icon?: ReactNode;\n label?: string;\n labelStyle?: StyleProp<TextStyle>;\n};\n"]}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type NativeScrollEvent, type NativeSyntheticEvent } from 'react-native';
|
|
3
|
+
type ScrollHandler = (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
4
|
+
type SetMinimized = (minimized: boolean) => void;
|
|
5
|
+
type MinimizedState = {
|
|
6
|
+
minimized: boolean;
|
|
7
|
+
setMinimized: SetMinimized;
|
|
8
|
+
};
|
|
9
|
+
export type MinimizeOnScroll = {
|
|
10
|
+
/** Pass to `AndroidGlassBottomTabs`' `minimized`. */
|
|
11
|
+
minimized: boolean;
|
|
12
|
+
/** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */
|
|
13
|
+
setMinimized: SetMinimized;
|
|
14
|
+
/** Pass to the list's `onScroll`, together with `scrollEventThrottle={16}`. */
|
|
15
|
+
onScroll: ScrollHandler;
|
|
16
|
+
};
|
|
17
|
+
/** Read by AndroidGlassBottomTabs; not part of the public API. */
|
|
18
|
+
export declare const MinimizedStateContext: React.Context<MinimizedState | null>;
|
|
19
|
+
/**
|
|
20
|
+
* Shares one minimize state between the tab bar and any number of lists, e.g. around a
|
|
21
|
+
* navigator's tabs, where the bar and the screens are different components. Inside it,
|
|
22
|
+
* `AndroidGlassBottomTabs` follows the shared state unless it gets a `minimized` prop.
|
|
23
|
+
*/
|
|
24
|
+
export declare function MinimizeOnScrollProvider({ children }: {
|
|
25
|
+
children?: React.ReactNode;
|
|
26
|
+
}): React.JSX.Element;
|
|
27
|
+
/**
|
|
28
|
+
* `onScroll` for a list inside `MinimizeOnScrollProvider`: scrolling down minimizes the tab bar,
|
|
29
|
+
* scrolling up (or reaching the top) expands it. Each list tracks its own position, and the
|
|
30
|
+
* component isn't re-rendered when the bar minimizes. Returns `undefined` outside a provider and
|
|
31
|
+
* on iOS and web, where the bar doesn't minimize, so the list sends no scroll events for nothing.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useMinimizeOnScrollHandler(): ScrollHandler | undefined;
|
|
34
|
+
/**
|
|
35
|
+
* Minimize state plus an `onScroll` for one list. Inside `MinimizeOnScrollProvider` it uses the
|
|
36
|
+
* shared state; outside, its own, which is enough when the list and the tab bar are in the same
|
|
37
|
+
* component.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useMinimizeOnScroll(): MinimizeOnScroll;
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=MinimizeOnScroll.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MinimizeOnScroll.d.ts","sourceRoot":"","sources":["../src/MinimizeOnScroll.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAE,KAAK,iBAAiB,EAAE,KAAK,oBAAoB,EAAY,MAAM,cAAc,CAAC;AAO3F,KAAK,aAAa,GAAG,CAAC,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;AAC9E,KAAK,YAAY,GAAG,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;AACjD,KAAK,cAAc,GAAG;IAAE,SAAS,EAAE,OAAO,CAAC;IAAC,YAAY,EAAE,YAAY,CAAA;CAAE,CAAC;AAEzE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qDAAqD;IACrD,SAAS,EAAE,OAAO,CAAC;IACnB,qFAAqF;IACrF,YAAY,EAAE,YAAY,CAAC;IAC3B,+EAA+E;IAC/E,QAAQ,EAAE,aAAa,CAAC;CACzB,CAAC;AAIF,kEAAkE;AAClE,eAAO,MAAM,qBAAqB,sCAAmD,CAAC;AAkCtF;;;;GAIG;AACH,wBAAgB,wBAAwB,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAAE,qBAOpF;AAED;;;;;GAKG;AACH,wBAAgB,0BAA0B,IAAI,aAAa,GAAG,SAAS,CAItE;AAED;;;;GAIG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CAMtD"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { Platform } from 'react-native';
|
|
3
|
+
/** Within this distance from the top of the list, the bar is always expanded. */
|
|
4
|
+
const TOP_ZONE = 24;
|
|
5
|
+
/** Smallest scroll step between two events that counts as a direction. */
|
|
6
|
+
const MIN_STEP = 3;
|
|
7
|
+
// Two contexts: lists only need the (stable) setter, so a minimize doesn't re-render screens.
|
|
8
|
+
const SetMinimizedContext = React.createContext(null);
|
|
9
|
+
/** Read by AndroidGlassBottomTabs; not part of the public API. */
|
|
10
|
+
export const MinimizedStateContext = React.createContext(null);
|
|
11
|
+
/** Minimize state whose setter only re-renders on a change (scroll events arrive every frame). */
|
|
12
|
+
function useMinimizedState() {
|
|
13
|
+
const [minimized, setState] = React.useState(false);
|
|
14
|
+
const current = React.useRef(false);
|
|
15
|
+
const setMinimized = React.useCallback((next) => {
|
|
16
|
+
if (current.current !== next) {
|
|
17
|
+
current.current = next;
|
|
18
|
+
setState(next);
|
|
19
|
+
}
|
|
20
|
+
}, []);
|
|
21
|
+
return React.useMemo(() => ({ minimized, setMinimized }), [minimized, setMinimized]);
|
|
22
|
+
}
|
|
23
|
+
/** Minimizes on scroll down; expands on scroll up and near the top. */
|
|
24
|
+
function useScrollHandler(setMinimized) {
|
|
25
|
+
const previousY = React.useRef(0);
|
|
26
|
+
return React.useCallback((event) => {
|
|
27
|
+
// Clamped to the scrollable range, so overscroll can't flip the direction for a frame.
|
|
28
|
+
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
29
|
+
const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);
|
|
30
|
+
const y = Math.min(Math.max(contentOffset.y, 0), maxY);
|
|
31
|
+
const step = y - previousY.current;
|
|
32
|
+
previousY.current = y;
|
|
33
|
+
if (y < TOP_ZONE)
|
|
34
|
+
setMinimized(false);
|
|
35
|
+
else if (step > MIN_STEP)
|
|
36
|
+
setMinimized(true);
|
|
37
|
+
else if (step < -MIN_STEP)
|
|
38
|
+
setMinimized(false);
|
|
39
|
+
}, [setMinimized]);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Shares one minimize state between the tab bar and any number of lists, e.g. around a
|
|
43
|
+
* navigator's tabs, where the bar and the screens are different components. Inside it,
|
|
44
|
+
* `AndroidGlassBottomTabs` follows the shared state unless it gets a `minimized` prop.
|
|
45
|
+
*/
|
|
46
|
+
export function MinimizeOnScrollProvider({ children }) {
|
|
47
|
+
const state = useMinimizedState();
|
|
48
|
+
return (<SetMinimizedContext.Provider value={state.setMinimized}>
|
|
49
|
+
<MinimizedStateContext.Provider value={state}>{children}</MinimizedStateContext.Provider>
|
|
50
|
+
</SetMinimizedContext.Provider>);
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* `onScroll` for a list inside `MinimizeOnScrollProvider`: scrolling down minimizes the tab bar,
|
|
54
|
+
* scrolling up (or reaching the top) expands it. Each list tracks its own position, and the
|
|
55
|
+
* component isn't re-rendered when the bar minimizes. Returns `undefined` outside a provider and
|
|
56
|
+
* on iOS and web, where the bar doesn't minimize, so the list sends no scroll events for nothing.
|
|
57
|
+
*/
|
|
58
|
+
export function useMinimizeOnScrollHandler() {
|
|
59
|
+
const setMinimized = React.useContext(SetMinimizedContext);
|
|
60
|
+
const onScroll = useScrollHandler(setMinimized ?? noop);
|
|
61
|
+
return setMinimized != null && Platform.OS === 'android' ? onScroll : undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Minimize state plus an `onScroll` for one list. Inside `MinimizeOnScrollProvider` it uses the
|
|
65
|
+
* shared state; outside, its own, which is enough when the list and the tab bar are in the same
|
|
66
|
+
* component.
|
|
67
|
+
*/
|
|
68
|
+
export function useMinimizeOnScroll() {
|
|
69
|
+
const shared = React.useContext(MinimizedStateContext);
|
|
70
|
+
const own = useMinimizedState();
|
|
71
|
+
const { minimized, setMinimized } = shared ?? own;
|
|
72
|
+
const onScroll = useScrollHandler(setMinimized);
|
|
73
|
+
return { minimized, setMinimized, onScroll };
|
|
74
|
+
}
|
|
75
|
+
function noop() { }
|
|
76
|
+
//# sourceMappingURL=MinimizeOnScroll.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MinimizeOnScroll.js","sourceRoot":"","sources":["../src/MinimizeOnScroll.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAAqD,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE3F,iFAAiF;AACjF,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,0EAA0E;AAC1E,MAAM,QAAQ,GAAG,CAAC,CAAC;AAenB,8FAA8F;AAC9F,MAAM,mBAAmB,GAAG,KAAK,CAAC,aAAa,CAAsB,IAAI,CAAC,CAAC;AAC3E,kEAAkE;AAClE,MAAM,CAAC,MAAM,qBAAqB,GAAG,KAAK,CAAC,aAAa,CAAwB,IAAI,CAAC,CAAC;AAEtF,kGAAkG;AAClG,SAAS,iBAAiB;IACxB,MAAM,CAAC,SAAS,EAA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,YAAY,EAAE,QAAQ,EAAE,CAAC;AAC/C,CAAC;AAED,SAAS,IAAI,KAAI,CAAC","sourcesContent":["import * as React from 'react';\nimport { type NativeScrollEvent, type NativeSyntheticEvent, Platform } from 'react-native';\n\n/** Within this distance from the top of the list, the bar is always expanded. */\nconst TOP_ZONE = 24;\n/** Smallest scroll step between two events that counts as a direction. */\nconst MIN_STEP = 3;\n\ntype ScrollHandler = (event: NativeSyntheticEvent<NativeScrollEvent>) => void;\ntype SetMinimized = (minimized: boolean) => void;\ntype MinimizedState = { minimized: boolean; setMinimized: SetMinimized };\n\nexport type MinimizeOnScroll = {\n /** Pass to `AndroidGlassBottomTabs`' `minimized`. */\n minimized: boolean;\n /** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */\n setMinimized: SetMinimized;\n /** Pass to the list's `onScroll`, together with `scrollEventThrottle={16}`. */\n onScroll: ScrollHandler;\n};\n\n// Two contexts: lists only need the (stable) setter, so a minimize doesn't re-render screens.\nconst SetMinimizedContext = React.createContext<SetMinimized | null>(null);\n/** Read by AndroidGlassBottomTabs; not part of the public API. */\nexport const MinimizedStateContext = React.createContext<MinimizedState | null>(null);\n\n/** Minimize state whose setter only re-renders on a change (scroll events arrive every frame). */\nfunction useMinimizedState(): MinimizedState {\n const [minimized, setState] = React.useState(false);\n const current = React.useRef(false);\n const setMinimized = React.useCallback((next: boolean) => {\n if (current.current !== next) {\n current.current = next;\n setState(next);\n }\n }, []);\n return React.useMemo(() => ({ minimized, setMinimized }), [minimized, setMinimized]);\n}\n\n/** Minimizes on scroll down; expands on scroll up and near the top. */\nfunction useScrollHandler(setMinimized: SetMinimized): ScrollHandler {\n const previousY = React.useRef(0);\n return React.useCallback(\n (event: NativeSyntheticEvent<NativeScrollEvent>) => {\n // Clamped to the scrollable range, so overscroll can't flip the direction for a frame.\n const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;\n const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);\n const y = Math.min(Math.max(contentOffset.y, 0), maxY);\n const step = y - previousY.current;\n previousY.current = y;\n if (y < TOP_ZONE) setMinimized(false);\n else if (step > MIN_STEP) setMinimized(true);\n else if (step < -MIN_STEP) setMinimized(false);\n },\n [setMinimized]\n );\n}\n\n/**\n * Shares one minimize state between the tab bar and any number of lists, e.g. around a\n * navigator's tabs, where the bar and the screens are different components. Inside it,\n * `AndroidGlassBottomTabs` follows the shared state unless it gets a `minimized` prop.\n */\nexport function MinimizeOnScrollProvider({ children }: { children?: React.ReactNode }) {\n const state = useMinimizedState();\n return (\n <SetMinimizedContext.Provider value={state.setMinimized}>\n <MinimizedStateContext.Provider value={state}>{children}</MinimizedStateContext.Provider>\n </SetMinimizedContext.Provider>\n );\n}\n\n/**\n * `onScroll` for a list inside `MinimizeOnScrollProvider`: scrolling down minimizes the tab bar,\n * scrolling up (or reaching the top) expands it. Each list tracks its own position, and the\n * component isn't re-rendered when the bar minimizes. Returns `undefined` outside a provider and\n * on iOS and web, where the bar doesn't minimize, so the list sends no scroll events for nothing.\n */\nexport function useMinimizeOnScrollHandler(): ScrollHandler | undefined {\n const setMinimized = React.useContext(SetMinimizedContext);\n const onScroll = useScrollHandler(setMinimized ?? noop);\n return setMinimized != null && Platform.OS === 'android' ? onScroll : undefined;\n}\n\n/**\n * Minimize state plus an `onScroll` for one list. Inside `MinimizeOnScrollProvider` it uses the\n * shared state; outside, its own, which is enough when the list and the tab bar are in the same\n * component.\n */\nexport function useMinimizeOnScroll(): MinimizeOnScroll {\n const shared = React.useContext(MinimizedStateContext);\n const own = useMinimizedState();\n const { minimized, setMinimized } = shared ?? own;\n const onScroll = useScrollHandler(setMinimized);\n return { minimized, setMinimized, onScroll };\n}\n\nfunction noop() {}\n"]}
|
package/build/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@ export { default as AndroidGlassToggle } from './AndroidGlassToggle';
|
|
|
4
4
|
export { default as AndroidGlassSlider } from './AndroidGlassSlider';
|
|
5
5
|
export { default as AndroidGlassBottomTabs } from './AndroidGlassBottomTabs';
|
|
6
6
|
export { default as AndroidGlassTab } from './AndroidGlassTab';
|
|
7
|
-
export { useMinimizeOnScroll, type MinimizeOnScroll } from './
|
|
7
|
+
export { MinimizeOnScrollProvider, useMinimizeOnScroll, useMinimizeOnScrollHandler, type MinimizeOnScroll, } from './MinimizeOnScroll';
|
|
8
8
|
export * from './AndroidGlassView.types';
|
|
9
9
|
export * from './AndroidGlassComponents.types';
|
|
10
10
|
//# sourceMappingURL=index.d.ts.map
|
package/build/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,EAC1B,KAAK,gBAAgB,GACtB,MAAM,oBAAoB,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC"}
|
package/build/index.js
CHANGED
|
@@ -6,7 +6,7 @@ export { default as AndroidGlassToggle } from './AndroidGlassToggle';
|
|
|
6
6
|
export { default as AndroidGlassSlider } from './AndroidGlassSlider';
|
|
7
7
|
export { default as AndroidGlassBottomTabs } from './AndroidGlassBottomTabs';
|
|
8
8
|
export { default as AndroidGlassTab } from './AndroidGlassTab';
|
|
9
|
-
export { useMinimizeOnScroll } from './
|
|
9
|
+
export { MinimizeOnScrollProvider, useMinimizeOnScroll, useMinimizeOnScrollHandler, } from './MinimizeOnScroll';
|
|
10
10
|
export * from './AndroidGlassView.types';
|
|
11
11
|
export * from './AndroidGlassComponents.types';
|
|
12
12
|
//# sourceMappingURL=index.js.map
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,wDAAwD;AACxD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,+FAA+F;AAC/F,wDAAwD;AACxD,OAAO,EAAE,OAAO,IAAI,gBAAgB,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AACrE,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAC/D,OAAO,EACL,wBAAwB,EACxB,mBAAmB,EACnB,0BAA0B,GAE3B,MAAM,oBAAoB,CAAC;AAC5B,cAAc,0BAA0B,CAAC;AACzC,cAAc,gCAAgC,CAAC","sourcesContent":["// Each component resolves to its native Android implementation (*.android.tsx) on Android, and\n// to a plain fallback with the same API on iOS and web.\nexport { default as AndroidGlassView } from './AndroidGlassView';\nexport { default as AndroidGlassButton } from './AndroidGlassButton';\nexport { default as AndroidGlassToggle } from './AndroidGlassToggle';\nexport { default as AndroidGlassSlider } from './AndroidGlassSlider';\nexport { default as AndroidGlassBottomTabs } from './AndroidGlassBottomTabs';\nexport { default as AndroidGlassTab } from './AndroidGlassTab';\nexport {\n MinimizeOnScrollProvider,\n useMinimizeOnScroll,\n useMinimizeOnScrollHandler,\n type MinimizeOnScroll,\n} from './MinimizeOnScroll';\nexport * from './AndroidGlassView.types';\nexport * from './AndroidGlassComponents.types';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "expo-android-glass-view",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Liquid Glass views, buttons, sliders and toggles for React Native on Android (Jetpack Compose, powered by Kyant0/AndroidLiquidGlass)",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -3,6 +3,7 @@ import * as React from 'react';
|
|
|
3
3
|
import { StyleSheet, View } from 'react-native';
|
|
4
4
|
|
|
5
5
|
import type { AndroidGlassBottomTabsProps } from './AndroidGlassComponents.types';
|
|
6
|
+
import { MinimizedStateContext } from './MinimizeOnScroll';
|
|
6
7
|
import { type NativeColor, toNativeColor } from './utils';
|
|
7
8
|
|
|
8
9
|
type IndexEvent = { nativeEvent: { index: number; eventCount: number } };
|
|
@@ -42,6 +43,9 @@ export default function AndroidGlassBottomTabs({
|
|
|
42
43
|
// up with earlier selections) from a current one.
|
|
43
44
|
const [eventCount, setEventCount] = React.useState(0);
|
|
44
45
|
const selected = selectedIndex ?? ownIndex;
|
|
46
|
+
// Inside a MinimizeOnScrollProvider, the bar follows the shared state unless `minimized` is given.
|
|
47
|
+
const shared = React.useContext(MinimizedStateContext);
|
|
48
|
+
const followsProvider = minimized === undefined;
|
|
45
49
|
return (
|
|
46
50
|
<NativeAndroidGlassBottomTabs
|
|
47
51
|
accessibilityRole="tablist"
|
|
@@ -50,7 +54,7 @@ export default function AndroidGlassBottomTabs({
|
|
|
50
54
|
selectedIndex={selected}
|
|
51
55
|
tabsCount={tabs.length}
|
|
52
56
|
mostRecentEventCount={eventCount}
|
|
53
|
-
minimized={minimized ?? false}
|
|
57
|
+
minimized={minimized ?? shared?.minimized ?? false}
|
|
54
58
|
accentColor={toNativeColor(accentColor)}
|
|
55
59
|
containerColor={toNativeColor(containerColor)}
|
|
56
60
|
onTabSelected={(event) => {
|
|
@@ -59,7 +63,11 @@ export default function AndroidGlassBottomTabs({
|
|
|
59
63
|
setOwnIndex(index);
|
|
60
64
|
onTabSelected?.(index);
|
|
61
65
|
}}
|
|
62
|
-
onMinimizedChange={(event) =>
|
|
66
|
+
onMinimizedChange={(event) => {
|
|
67
|
+
const value = event.nativeEvent.minimized;
|
|
68
|
+
if (followsProvider) shared?.setMinimized(value);
|
|
69
|
+
onMinimizedChange?.(value);
|
|
70
|
+
}}>
|
|
63
71
|
{tabs.map((tab, index) => (
|
|
64
72
|
// The native bar handles taps and drags, and draws these views itself (inside the glass
|
|
65
73
|
// and, tinted, under the droplet), so they must stay real views and not take touches.
|
|
@@ -52,13 +52,14 @@ export type AndroidGlassBottomTabsProps = ViewProps & {
|
|
|
52
52
|
onTabSelected?: (index: number) => void;
|
|
53
53
|
/**
|
|
54
54
|
* Minimizes the bar, like iOS 26 tab bars on scroll: it gets shorter and narrower, each tab keeps
|
|
55
|
-
* only its first child (the icon) and the rest (the label) fades out. Animated natively
|
|
56
|
-
*
|
|
55
|
+
* only its first child (the icon) and the rest (the label) fades out. Animated natively. Inside a
|
|
56
|
+
* `MinimizeOnScrollProvider`, leave it out: the bar follows the provider. Android only.
|
|
57
57
|
*/
|
|
58
58
|
minimized?: boolean;
|
|
59
59
|
/**
|
|
60
|
-
* Called with `false` when the user expands the minimized bar by touching it.
|
|
61
|
-
* `
|
|
60
|
+
* Called with `false` when the user expands the minimized bar by touching it. With
|
|
61
|
+
* `useMinimizeOnScroll`, pass its `setMinimized`; inside a `MinimizeOnScrollProvider` it isn't
|
|
62
|
+
* needed.
|
|
62
63
|
*/
|
|
63
64
|
onMinimizedChange?: (minimized: boolean) => void;
|
|
64
65
|
/** Colour the selected tab's content takes under the droplet. Default system blue. */
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { type NativeScrollEvent, type NativeSyntheticEvent, Platform } from 'react-native';
|
|
3
|
+
|
|
4
|
+
/** Within this distance from the top of the list, the bar is always expanded. */
|
|
5
|
+
const TOP_ZONE = 24;
|
|
6
|
+
/** Smallest scroll step between two events that counts as a direction. */
|
|
7
|
+
const MIN_STEP = 3;
|
|
8
|
+
|
|
9
|
+
type ScrollHandler = (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
10
|
+
type SetMinimized = (minimized: boolean) => void;
|
|
11
|
+
type MinimizedState = { minimized: boolean; setMinimized: SetMinimized };
|
|
12
|
+
|
|
13
|
+
export type MinimizeOnScroll = {
|
|
14
|
+
/** Pass to `AndroidGlassBottomTabs`' `minimized`. */
|
|
15
|
+
minimized: boolean;
|
|
16
|
+
/** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */
|
|
17
|
+
setMinimized: SetMinimized;
|
|
18
|
+
/** Pass to the list's `onScroll`, together with `scrollEventThrottle={16}`. */
|
|
19
|
+
onScroll: ScrollHandler;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
// Two contexts: lists only need the (stable) setter, so a minimize doesn't re-render screens.
|
|
23
|
+
const SetMinimizedContext = React.createContext<SetMinimized | null>(null);
|
|
24
|
+
/** Read by AndroidGlassBottomTabs; not part of the public API. */
|
|
25
|
+
export const MinimizedStateContext = React.createContext<MinimizedState | null>(null);
|
|
26
|
+
|
|
27
|
+
/** Minimize state whose setter only re-renders on a change (scroll events arrive every frame). */
|
|
28
|
+
function useMinimizedState(): MinimizedState {
|
|
29
|
+
const [minimized, setState] = React.useState(false);
|
|
30
|
+
const current = React.useRef(false);
|
|
31
|
+
const setMinimized = React.useCallback((next: boolean) => {
|
|
32
|
+
if (current.current !== next) {
|
|
33
|
+
current.current = next;
|
|
34
|
+
setState(next);
|
|
35
|
+
}
|
|
36
|
+
}, []);
|
|
37
|
+
return React.useMemo(() => ({ minimized, setMinimized }), [minimized, setMinimized]);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Minimizes on scroll down; expands on scroll up and near the top. */
|
|
41
|
+
function useScrollHandler(setMinimized: SetMinimized): ScrollHandler {
|
|
42
|
+
const previousY = React.useRef(0);
|
|
43
|
+
return React.useCallback(
|
|
44
|
+
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
45
|
+
// Clamped to the scrollable range, so overscroll can't flip the direction for a frame.
|
|
46
|
+
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
47
|
+
const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);
|
|
48
|
+
const y = Math.min(Math.max(contentOffset.y, 0), maxY);
|
|
49
|
+
const step = y - previousY.current;
|
|
50
|
+
previousY.current = y;
|
|
51
|
+
if (y < TOP_ZONE) setMinimized(false);
|
|
52
|
+
else if (step > MIN_STEP) setMinimized(true);
|
|
53
|
+
else if (step < -MIN_STEP) setMinimized(false);
|
|
54
|
+
},
|
|
55
|
+
[setMinimized]
|
|
56
|
+
);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* Shares one minimize state between the tab bar and any number of lists, e.g. around a
|
|
61
|
+
* navigator's tabs, where the bar and the screens are different components. Inside it,
|
|
62
|
+
* `AndroidGlassBottomTabs` follows the shared state unless it gets a `minimized` prop.
|
|
63
|
+
*/
|
|
64
|
+
export function MinimizeOnScrollProvider({ children }: { children?: React.ReactNode }) {
|
|
65
|
+
const state = useMinimizedState();
|
|
66
|
+
return (
|
|
67
|
+
<SetMinimizedContext.Provider value={state.setMinimized}>
|
|
68
|
+
<MinimizedStateContext.Provider value={state}>{children}</MinimizedStateContext.Provider>
|
|
69
|
+
</SetMinimizedContext.Provider>
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* `onScroll` for a list inside `MinimizeOnScrollProvider`: scrolling down minimizes the tab bar,
|
|
75
|
+
* scrolling up (or reaching the top) expands it. Each list tracks its own position, and the
|
|
76
|
+
* component isn't re-rendered when the bar minimizes. Returns `undefined` outside a provider and
|
|
77
|
+
* on iOS and web, where the bar doesn't minimize, so the list sends no scroll events for nothing.
|
|
78
|
+
*/
|
|
79
|
+
export function useMinimizeOnScrollHandler(): ScrollHandler | undefined {
|
|
80
|
+
const setMinimized = React.useContext(SetMinimizedContext);
|
|
81
|
+
const onScroll = useScrollHandler(setMinimized ?? noop);
|
|
82
|
+
return setMinimized != null && Platform.OS === 'android' ? onScroll : undefined;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Minimize state plus an `onScroll` for one list. Inside `MinimizeOnScrollProvider` it uses the
|
|
87
|
+
* shared state; outside, its own, which is enough when the list and the tab bar are in the same
|
|
88
|
+
* component.
|
|
89
|
+
*/
|
|
90
|
+
export function useMinimizeOnScroll(): MinimizeOnScroll {
|
|
91
|
+
const shared = React.useContext(MinimizedStateContext);
|
|
92
|
+
const own = useMinimizedState();
|
|
93
|
+
const { minimized, setMinimized } = shared ?? own;
|
|
94
|
+
const onScroll = useScrollHandler(setMinimized);
|
|
95
|
+
return { minimized, setMinimized, onScroll };
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
function noop() {}
|
package/src/index.ts
CHANGED
|
@@ -6,6 +6,11 @@ export { default as AndroidGlassToggle } from './AndroidGlassToggle';
|
|
|
6
6
|
export { default as AndroidGlassSlider } from './AndroidGlassSlider';
|
|
7
7
|
export { default as AndroidGlassBottomTabs } from './AndroidGlassBottomTabs';
|
|
8
8
|
export { default as AndroidGlassTab } from './AndroidGlassTab';
|
|
9
|
-
export {
|
|
9
|
+
export {
|
|
10
|
+
MinimizeOnScrollProvider,
|
|
11
|
+
useMinimizeOnScroll,
|
|
12
|
+
useMinimizeOnScrollHandler,
|
|
13
|
+
type MinimizeOnScroll,
|
|
14
|
+
} from './MinimizeOnScroll';
|
|
10
15
|
export * from './AndroidGlassView.types';
|
|
11
16
|
export * from './AndroidGlassComponents.types';
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
|
|
2
|
-
export type MinimizeOnScroll = {
|
|
3
|
-
/** Pass to `AndroidGlassBottomTabs`' `minimized`. */
|
|
4
|
-
minimized: boolean;
|
|
5
|
-
/** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */
|
|
6
|
-
setMinimized: (minimized: boolean) => void;
|
|
7
|
-
/** Pass to the main list's `onScroll`, together with `scrollEventThrottle={16}`. */
|
|
8
|
-
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Minimizes `AndroidGlassBottomTabs` while the user scrolls down a list, and expands it when they
|
|
12
|
-
* scroll up or get back to the top, like iOS 26 tab bars. Works with ScrollView, FlatList,
|
|
13
|
-
* SectionList and any list that reports `onScroll`. JS only decides the state; the animation
|
|
14
|
-
* runs natively.
|
|
15
|
-
*/
|
|
16
|
-
export declare function useMinimizeOnScroll(): MinimizeOnScroll;
|
|
17
|
-
//# sourceMappingURL=useMinimizeOnScroll.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMinimizeOnScroll.d.ts","sourceRoot":"","sources":["../src/useMinimizeOnScroll.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAC;AAO5E,MAAM,MAAM,gBAAgB,GAAG;IAC7B,qDAAqD;IACrD,SAAS,EAAE,OAAO,CAAC;IACnB,qFAAqF;IACrF,YAAY,EAAE,CAAC,SAAS,EAAE,OAAO,KAAK,IAAI,CAAC;IAC3C,oFAAoF;IACpF,QAAQ,EAAE,CAAC,KAAK,EAAE,oBAAoB,CAAC,iBAAiB,CAAC,KAAK,IAAI,CAAC;CACpE,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,mBAAmB,IAAI,gBAAgB,CA6BtD"}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import { useCallback, useRef, useState } from 'react';
|
|
2
|
-
/** Within this distance from the top of the list, the bar is always expanded. */
|
|
3
|
-
const TOP_ZONE = 24;
|
|
4
|
-
/** Smallest scroll step between two events that counts as a direction. */
|
|
5
|
-
const MIN_STEP = 3;
|
|
6
|
-
/**
|
|
7
|
-
* Minimizes `AndroidGlassBottomTabs` while the user scrolls down a list, and expands it when they
|
|
8
|
-
* scroll up or get back to the top, like iOS 26 tab bars. Works with ScrollView, FlatList,
|
|
9
|
-
* SectionList and any list that reports `onScroll`. JS only decides the state; the animation
|
|
10
|
-
* runs natively.
|
|
11
|
-
*/
|
|
12
|
-
export function useMinimizeOnScroll() {
|
|
13
|
-
const [minimized, setMinimizedState] = useState(false);
|
|
14
|
-
const current = useRef(false);
|
|
15
|
-
const previousY = useRef(0);
|
|
16
|
-
const setMinimized = useCallback((next) => {
|
|
17
|
-
// Scroll events arrive every frame; only a change re-renders.
|
|
18
|
-
if (current.current !== next) {
|
|
19
|
-
current.current = next;
|
|
20
|
-
setMinimizedState(next);
|
|
21
|
-
}
|
|
22
|
-
}, []);
|
|
23
|
-
const onScroll = useCallback((event) => {
|
|
24
|
-
// Clamped to the scrollable range, so overscroll can't flip the direction for a frame.
|
|
25
|
-
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
26
|
-
const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);
|
|
27
|
-
const y = Math.min(Math.max(contentOffset.y, 0), maxY);
|
|
28
|
-
const step = y - previousY.current;
|
|
29
|
-
previousY.current = y;
|
|
30
|
-
if (y < TOP_ZONE)
|
|
31
|
-
setMinimized(false);
|
|
32
|
-
else if (step > MIN_STEP)
|
|
33
|
-
setMinimized(true);
|
|
34
|
-
else if (step < -MIN_STEP)
|
|
35
|
-
setMinimized(false);
|
|
36
|
-
}, [setMinimized]);
|
|
37
|
-
return { minimized, setMinimized, onScroll };
|
|
38
|
-
}
|
|
39
|
-
//# sourceMappingURL=useMinimizeOnScroll.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"useMinimizeOnScroll.js","sourceRoot":"","sources":["../src/useMinimizeOnScroll.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAGtD,iFAAiF;AACjF,MAAM,QAAQ,GAAG,EAAE,CAAC;AACpB,0EAA0E;AAC1E,MAAM,QAAQ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AC,CAAC;IACjD,CAAC,EACD,CAAC,YAAY,CAAC,CACf,CAAC;IAEF,OAAO,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,CAAC;AAC/C,CAAC","sourcesContent":["import { useCallback, useRef, useState } from 'react';\nimport type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';\n\n/** Within this distance from the top of the list, the bar is always expanded. */\nconst TOP_ZONE = 24;\n/** Smallest scroll step between two events that counts as a direction. */\nconst MIN_STEP = 3;\n\nexport type MinimizeOnScroll = {\n /** Pass to `AndroidGlassBottomTabs`' `minimized`. */\n minimized: boolean;\n /** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */\n setMinimized: (minimized: boolean) => void;\n /** Pass to the main list's `onScroll`, together with `scrollEventThrottle={16}`. */\n onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;\n};\n\n/**\n * Minimizes `AndroidGlassBottomTabs` while the user scrolls down a list, and expands it when they\n * scroll up or get back to the top, like iOS 26 tab bars. Works with ScrollView, FlatList,\n * SectionList and any list that reports `onScroll`. JS only decides the state; the animation\n * runs natively.\n */\nexport function useMinimizeOnScroll(): MinimizeOnScroll {\n const [minimized, setMinimizedState] = useState(false);\n const current = useRef(false);\n const previousY = useRef(0);\n\n const setMinimized = useCallback((next: boolean) => {\n // Scroll events arrive every frame; only a change re-renders.\n if (current.current !== next) {\n current.current = next;\n setMinimizedState(next);\n }\n }, []);\n\n const onScroll = useCallback(\n (event: NativeSyntheticEvent<NativeScrollEvent>) => {\n // Clamped to the scrollable range, so overscroll can't flip the direction for a frame.\n const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;\n const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);\n const y = Math.min(Math.max(contentOffset.y, 0), maxY);\n const step = y - previousY.current;\n previousY.current = y;\n if (y < TOP_ZONE) setMinimized(false);\n else if (step > MIN_STEP) setMinimized(true);\n else if (step < -MIN_STEP) setMinimized(false);\n },\n [setMinimized]\n );\n\n return { minimized, setMinimized, onScroll };\n}\n"]}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { useCallback, useRef, useState } from 'react';
|
|
2
|
-
import type { NativeScrollEvent, NativeSyntheticEvent } from 'react-native';
|
|
3
|
-
|
|
4
|
-
/** Within this distance from the top of the list, the bar is always expanded. */
|
|
5
|
-
const TOP_ZONE = 24;
|
|
6
|
-
/** Smallest scroll step between two events that counts as a direction. */
|
|
7
|
-
const MIN_STEP = 3;
|
|
8
|
-
|
|
9
|
-
export type MinimizeOnScroll = {
|
|
10
|
-
/** Pass to `AndroidGlassBottomTabs`' `minimized`. */
|
|
11
|
-
minimized: boolean;
|
|
12
|
-
/** Pass to `AndroidGlassBottomTabs`' `onMinimizedChange`. Can also force a state. */
|
|
13
|
-
setMinimized: (minimized: boolean) => void;
|
|
14
|
-
/** Pass to the main list's `onScroll`, together with `scrollEventThrottle={16}`. */
|
|
15
|
-
onScroll: (event: NativeSyntheticEvent<NativeScrollEvent>) => void;
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
/**
|
|
19
|
-
* Minimizes `AndroidGlassBottomTabs` while the user scrolls down a list, and expands it when they
|
|
20
|
-
* scroll up or get back to the top, like iOS 26 tab bars. Works with ScrollView, FlatList,
|
|
21
|
-
* SectionList and any list that reports `onScroll`. JS only decides the state; the animation
|
|
22
|
-
* runs natively.
|
|
23
|
-
*/
|
|
24
|
-
export function useMinimizeOnScroll(): MinimizeOnScroll {
|
|
25
|
-
const [minimized, setMinimizedState] = useState(false);
|
|
26
|
-
const current = useRef(false);
|
|
27
|
-
const previousY = useRef(0);
|
|
28
|
-
|
|
29
|
-
const setMinimized = useCallback((next: boolean) => {
|
|
30
|
-
// Scroll events arrive every frame; only a change re-renders.
|
|
31
|
-
if (current.current !== next) {
|
|
32
|
-
current.current = next;
|
|
33
|
-
setMinimizedState(next);
|
|
34
|
-
}
|
|
35
|
-
}, []);
|
|
36
|
-
|
|
37
|
-
const onScroll = useCallback(
|
|
38
|
-
(event: NativeSyntheticEvent<NativeScrollEvent>) => {
|
|
39
|
-
// Clamped to the scrollable range, so overscroll can't flip the direction for a frame.
|
|
40
|
-
const { contentOffset, contentSize, layoutMeasurement } = event.nativeEvent;
|
|
41
|
-
const maxY = Math.max(contentSize.height - layoutMeasurement.height, 0);
|
|
42
|
-
const y = Math.min(Math.max(contentOffset.y, 0), maxY);
|
|
43
|
-
const step = y - previousY.current;
|
|
44
|
-
previousY.current = y;
|
|
45
|
-
if (y < TOP_ZONE) setMinimized(false);
|
|
46
|
-
else if (step > MIN_STEP) setMinimized(true);
|
|
47
|
-
else if (step < -MIN_STEP) setMinimized(false);
|
|
48
|
-
},
|
|
49
|
-
[setMinimized]
|
|
50
|
-
);
|
|
51
|
-
|
|
52
|
-
return { minimized, setMinimized, onScroll };
|
|
53
|
-
}
|