expo-android-glass-view 0.1.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/CHANGELOG.md +13 -0
- package/LICENSE +55 -0
- package/README.md +260 -0
- package/THIRD_PARTY_NOTICES.md +44 -0
- package/android/build.gradle +39 -0
- package/android/src/main/AndroidManifest.xml +2 -0
- package/android/src/main/java/expo/modules/androidglassview/AndroidGlassBottomTabs.kt +162 -0
- package/android/src/main/java/expo/modules/androidglassview/AndroidGlassButton.kt +45 -0
- package/android/src/main/java/expo/modules/androidglassview/AndroidGlassSlider.kt +84 -0
- package/android/src/main/java/expo/modules/androidglassview/AndroidGlassToggle.kt +59 -0
- package/android/src/main/java/expo/modules/androidglassview/AndroidGlassView.kt +21 -0
- package/android/src/main/java/expo/modules/androidglassview/ControlledProp.kt +30 -0
- package/android/src/main/java/expo/modules/androidglassview/ExpoAndroidGlassViewModule.kt +210 -0
- package/android/src/main/java/expo/modules/androidglassview/GlassHostView.kt +346 -0
- package/android/src/main/java/expo/modules/androidglassview/GlassRegistry.kt +31 -0
- package/android/src/main/java/expo/modules/androidglassview/GlassSurface.kt +96 -0
- package/android/src/main/java/expo/modules/androidglassview/ViewBackdrop.kt +151 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/Backdrop.kt +25 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/BackdropEffectScope.kt +82 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/DrawBackdropModifier.kt +397 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/Platform.kt +18 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/RuntimeShader.kt +94 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/RuntimeShaderCache.kt +28 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/Backdrop.kt +45 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/CanvasBackdrop.kt +43 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/CombinedBackdrop.kt +107 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/EmptyBackdrop.kt +33 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/LayerBackdrop.kt +82 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/backdrops/LayerBackdropModifier.kt +77 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/Blur.kt +37 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/ColorFilter.kt +83 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/Lens.kt +117 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/effects/RenderEffect.kt +41 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/Highlight.kt +36 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightModifier.kt +174 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/highlight/HighlightStyle.kt +146 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/InverseLayerScope.kt +138 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/LayerRecorder.kt +34 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Outline.kt +26 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Paint.kt +24 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/RenderEffect.kt +58 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/Shaders.kt +206 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/internal/ShapeProvider.kt +52 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadow.kt +49 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/InnerShadowModifier.kt +166 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/Shadow.kt +35 -0
- package/android/src/main/java/expo/modules/androidglassview/backdrop/shadow/ShadowModifier.kt +145 -0
- package/android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt +176 -0
- package/android/src/main/java/expo/modules/androidglassview/components/CapsuleShape.kt +10 -0
- package/android/src/main/java/expo/modules/androidglassview/components/DampedDragAnimation.kt +152 -0
- package/android/src/main/java/expo/modules/androidglassview/components/DragGestureInspector.kt +91 -0
- package/android/src/main/java/expo/modules/androidglassview/components/InteractiveHighlight.kt +127 -0
- package/android/src/main/java/expo/modules/androidglassview/components/LiquidBottomTabs.kt +471 -0
- package/android/src/main/java/expo/modules/androidglassview/components/LiquidButton.kt +111 -0
- package/android/src/main/java/expo/modules/androidglassview/components/LiquidSlider.kt +227 -0
- package/android/src/main/java/expo/modules/androidglassview/components/LiquidToggle.kt +220 -0
- package/android/src/main/java/expo/modules/androidglassview/components/TabsFrame.kt +18 -0
- package/build/AndroidGlassBottomTabs.android.d.ts +4 -0
- package/build/AndroidGlassBottomTabs.android.d.ts.map +1 -0
- package/build/AndroidGlassBottomTabs.android.js +42 -0
- package/build/AndroidGlassBottomTabs.android.js.map +1 -0
- package/build/AndroidGlassBottomTabs.d.ts +5 -0
- package/build/AndroidGlassBottomTabs.d.ts.map +1 -0
- package/build/AndroidGlassBottomTabs.js +34 -0
- package/build/AndroidGlassBottomTabs.js.map +1 -0
- package/build/AndroidGlassButton.android.d.ts +4 -0
- package/build/AndroidGlassButton.android.d.ts.map +1 -0
- package/build/AndroidGlassButton.android.js +32 -0
- package/build/AndroidGlassButton.android.js.map +1 -0
- package/build/AndroidGlassButton.d.ts +5 -0
- package/build/AndroidGlassButton.d.ts.map +1 -0
- package/build/AndroidGlassButton.js +38 -0
- package/build/AndroidGlassButton.js.map +1 -0
- package/build/AndroidGlassComponents.types.d.ts +71 -0
- package/build/AndroidGlassComponents.types.d.ts.map +1 -0
- package/build/AndroidGlassComponents.types.js +2 -0
- package/build/AndroidGlassComponents.types.js.map +1 -0
- package/build/AndroidGlassSlider.android.d.ts +4 -0
- package/build/AndroidGlassSlider.android.d.ts.map +1 -0
- package/build/AndroidGlassSlider.android.js +27 -0
- package/build/AndroidGlassSlider.android.js.map +1 -0
- package/build/AndroidGlassSlider.d.ts +5 -0
- package/build/AndroidGlassSlider.d.ts.map +1 -0
- package/build/AndroidGlassSlider.js +47 -0
- package/build/AndroidGlassSlider.js.map +1 -0
- package/build/AndroidGlassTab.d.ts +9 -0
- package/build/AndroidGlassTab.d.ts.map +1 -0
- package/build/AndroidGlassTab.js +22 -0
- package/build/AndroidGlassTab.js.map +1 -0
- package/build/AndroidGlassToggle.android.d.ts +4 -0
- package/build/AndroidGlassToggle.android.d.ts.map +1 -0
- package/build/AndroidGlassToggle.android.js +27 -0
- package/build/AndroidGlassToggle.android.js.map +1 -0
- package/build/AndroidGlassToggle.d.ts +5 -0
- package/build/AndroidGlassToggle.d.ts.map +1 -0
- package/build/AndroidGlassToggle.js +7 -0
- package/build/AndroidGlassToggle.js.map +1 -0
- package/build/AndroidGlassView.android.d.ts +4 -0
- package/build/AndroidGlassView.android.d.ts.map +1 -0
- package/build/AndroidGlassView.android.js +10 -0
- package/build/AndroidGlassView.android.js.map +1 -0
- package/build/AndroidGlassView.d.ts +8 -0
- package/build/AndroidGlassView.d.ts.map +1 -0
- package/build/AndroidGlassView.js +18 -0
- package/build/AndroidGlassView.js.map +1 -0
- package/build/AndroidGlassView.types.d.ts +34 -0
- package/build/AndroidGlassView.types.d.ts.map +1 -0
- package/build/AndroidGlassView.types.js +2 -0
- package/build/AndroidGlassView.types.js.map +1 -0
- package/build/index.d.ts +10 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +12 -0
- package/build/index.js.map +1 -0
- package/build/useMinimizeOnScroll.d.ts +17 -0
- package/build/useMinimizeOnScroll.d.ts.map +1 -0
- package/build/useMinimizeOnScroll.js +39 -0
- package/build/useMinimizeOnScroll.js.map +1 -0
- package/build/utils.d.ts +5 -0
- package/build/utils.d.ts.map +1 -0
- package/build/utils.js +9 -0
- package/build/utils.js.map +1 -0
- package/expo-module.config.json +6 -0
- package/package.json +58 -0
- package/src/AndroidGlassBottomTabs.android.tsx +93 -0
- package/src/AndroidGlassBottomTabs.tsx +59 -0
- package/src/AndroidGlassButton.android.tsx +70 -0
- package/src/AndroidGlassButton.tsx +70 -0
- package/src/AndroidGlassComponents.types.ts +76 -0
- package/src/AndroidGlassSlider.android.tsx +70 -0
- package/src/AndroidGlassSlider.tsx +78 -0
- package/src/AndroidGlassTab.tsx +29 -0
- package/src/AndroidGlassToggle.android.tsx +64 -0
- package/src/AndroidGlassToggle.tsx +22 -0
- package/src/AndroidGlassView.android.tsx +41 -0
- package/src/AndroidGlassView.tsx +41 -0
- package/src/AndroidGlassView.types.ts +34 -0
- package/src/index.ts +11 -0
- package/src/useMinimizeOnScroll.ts +53 -0
- package/src/utils.ts +10 -0
- package/tsconfig.json +28 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 — 2026-09-10
|
|
4
|
+
|
|
5
|
+
First release.
|
|
6
|
+
|
|
7
|
+
- `AndroidGlassView`: a Liquid Glass container (blur, lens refraction, vibrancy, highlight, shadow)
|
|
8
|
+
whose backdrop is the live React Native screen behind it.
|
|
9
|
+
- `AndroidGlassButton`, `AndroidGlassToggle`, `AndroidGlassSlider`, `AndroidGlassBottomTabs` and
|
|
10
|
+
`AndroidGlassTab`: Kyant's Backdrop Catalog components, driven from React Native.
|
|
11
|
+
- `useMinimizeOnScroll` and the tab bar's `minimized` prop: the tab bar shrinks while a list
|
|
12
|
+
scrolls down and comes back on scroll up or touch, like iOS 26. Animated natively.
|
|
13
|
+
- iOS and web: plain fallbacks with the same API.
|
package/LICENSE
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
|
|
16
|
+
|
|
17
|
+
"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
|
|
18
|
+
|
|
19
|
+
"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
|
|
20
|
+
|
|
21
|
+
"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
|
|
22
|
+
|
|
23
|
+
"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
|
|
24
|
+
|
|
25
|
+
"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
|
|
26
|
+
|
|
27
|
+
"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
|
|
28
|
+
|
|
29
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
|
|
30
|
+
|
|
31
|
+
2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
|
|
32
|
+
|
|
33
|
+
3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
|
|
34
|
+
|
|
35
|
+
4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
|
|
36
|
+
|
|
37
|
+
You must give any other recipients of the Work or Derivative Works a copy of this License; and
|
|
38
|
+
|
|
39
|
+
You must cause any modified files to carry prominent notices stating that You changed the files; and
|
|
40
|
+
|
|
41
|
+
You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
|
|
42
|
+
|
|
43
|
+
If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
|
|
44
|
+
|
|
45
|
+
5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
|
|
46
|
+
|
|
47
|
+
6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
|
|
48
|
+
|
|
49
|
+
7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
|
|
50
|
+
|
|
51
|
+
8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
|
|
52
|
+
|
|
53
|
+
9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
|
|
54
|
+
|
|
55
|
+
END OF TERMS AND CONDITIONS
|
package/README.md
ADDED
|
@@ -0,0 +1,260 @@
|
|
|
1
|
+
# expo-android-glass-view
|
|
2
|
+
|
|
3
|
+
Liquid Glass for React Native on **Android**: real refraction, blur, vibrancy and rim
|
|
4
|
+
highlights behind any React content, rendered with Jetpack Compose — plus ready-made glass
|
|
5
|
+
buttons, toggles, sliders and a bottom tab bar.
|
|
6
|
+
|
|
7
|
+
The glass effects and the components come from
|
|
8
|
+
[Kyant0/AndroidLiquidGlass](https://github.com/Kyant0/AndroidLiquidGlass). The part that lets
|
|
9
|
+
the glass see the React Native screen behind it is adapted from
|
|
10
|
+
[QWEA0/Liquid-Glass-Android](https://github.com/QWEA0/Liquid-Glass-Android).
|
|
11
|
+
|
|
12
|
+
> **Status:** 0.1, the first release. APIs may still change before 1.0.
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import {
|
|
16
|
+
AndroidGlassView,
|
|
17
|
+
AndroidGlassButton,
|
|
18
|
+
AndroidGlassToggle,
|
|
19
|
+
AndroidGlassSlider,
|
|
20
|
+
AndroidGlassBottomTabs,
|
|
21
|
+
AndroidGlassTab,
|
|
22
|
+
useMinimizeOnScroll,
|
|
23
|
+
} from 'expo-android-glass-view';
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
No wrapper or provider is needed: every glass component samples whatever is drawn behind it in
|
|
27
|
+
the same window, and keeps up with scrolling lists, animations and layout changes.
|
|
28
|
+
|
|
29
|
+
## Platforms
|
|
30
|
+
|
|
31
|
+
| Platform | Result |
|
|
32
|
+
| --- | --- |
|
|
33
|
+
| Android 13+ (API 33) | Full effect: refraction, chromatic aberration, blur, vibrancy |
|
|
34
|
+
| Android 12 (API 31–32) | Blur and vibrancy, no refraction (needs AGSL runtime shaders) |
|
|
35
|
+
| Android 11 and older | Plain translucent surface (`fallbackColor`) |
|
|
36
|
+
| iOS, web | Same components, plain fallbacks with the same API — no crash |
|
|
37
|
+
|
|
38
|
+
Requires a development build (it is a native module, so it does not run in Expo Go) and the
|
|
39
|
+
React Native New Architecture. Built against Expo SDK 57 / React Native 0.86.
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```sh
|
|
44
|
+
npx expo install expo-android-glass-view
|
|
45
|
+
npx expo run:android
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
For bare React Native apps, [install Expo Modules](https://docs.expo.dev/bare/installing-expo-modules/) first.
|
|
49
|
+
|
|
50
|
+
## `AndroidGlassView`
|
|
51
|
+
|
|
52
|
+
A container: children render on top of the glass and stay fully interactive.
|
|
53
|
+
|
|
54
|
+
```tsx
|
|
55
|
+
<AndroidGlassView style={{ padding: 20 }} cornerRadius={24}>
|
|
56
|
+
<Text>Anything</Text>
|
|
57
|
+
</AndroidGlassView>
|
|
58
|
+
```
|
|
59
|
+
|
|
60
|
+
Accepts every `View` prop plus:
|
|
61
|
+
|
|
62
|
+
| Prop | Type | Default | Description |
|
|
63
|
+
| --- | --- | --- | --- |
|
|
64
|
+
| `cornerRadius` | `number` | `style.borderRadius`, else `24` | Corner radius of the glass shape in dp. Use a large value (e.g. `999`) for a capsule. |
|
|
65
|
+
| `blurRadius` | `number` | `2` | Backdrop blur in dp. `0` disables it. |
|
|
66
|
+
| `refractionHeight` | `number` | `12` | Width of the refracting rim in dp. `0` disables refraction. |
|
|
67
|
+
| `refractionAmount` | `number` | `24` | How far content is bent at the rim, in dp. |
|
|
68
|
+
| `chromaticAberration` | `boolean` | `false` | Split the refraction per colour channel (prism fringe). |
|
|
69
|
+
| `depthEffect` | `boolean` | `false` | Stronger, depth-like bending towards the rim. |
|
|
70
|
+
| `vibrancy` | `boolean` | `true` | Boost the saturation of what is behind the glass. |
|
|
71
|
+
| `highlight` | `boolean` | `true` | Specular highlight along the rim. |
|
|
72
|
+
| `shadow` | `boolean` | `true` | Soft drop shadow around the shape. |
|
|
73
|
+
| `tintColor` | `ColorValue` | — | Colour tint mixed into the glass. |
|
|
74
|
+
| `surfaceColor` | `ColorValue` | — | Flat colour painted over the glass, on top of the refraction. |
|
|
75
|
+
| `fallbackColor` | `ColorValue` | `rgba(255,255,255,0.7)` | Surface used where the effect cannot run (see *Platforms*). |
|
|
76
|
+
|
|
77
|
+
Don't set `backgroundColor` on a glass view — it would paint over the effect. Use `tintColor`
|
|
78
|
+
or `surfaceColor` instead.
|
|
79
|
+
|
|
80
|
+
## `AndroidGlassButton`
|
|
81
|
+
|
|
82
|
+
Kyant's liquid button: while pressed, the glass swells, stretches towards the finger and a
|
|
83
|
+
highlight follows it.
|
|
84
|
+
|
|
85
|
+
```tsx
|
|
86
|
+
<AndroidGlassButton title="Save" onPress={save} />
|
|
87
|
+
<AndroidGlassButton title="Continue" tintColor="#0088FF" onPress={next} />
|
|
88
|
+
<AndroidGlassButton surfaceColor="rgba(255, 255, 255, 0.3)" onPress={share}>
|
|
89
|
+
<Ionicons name="share-outline" size={18} />
|
|
90
|
+
<Text>Share</Text>
|
|
91
|
+
</AndroidGlassButton>
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Takes every `AndroidGlassView` prop (`cornerRadius` defaults to a capsule) plus:
|
|
95
|
+
|
|
96
|
+
| Prop | Type | Default | Description |
|
|
97
|
+
| --- | --- | --- | --- |
|
|
98
|
+
| `onPress` | `() => void` | — | Called on tap. |
|
|
99
|
+
| `title` | `string` | — | Convenience label (15 sp; white on a tinted button). |
|
|
100
|
+
| `titleStyle` | `TextStyle` | — | Style for `title`. |
|
|
101
|
+
| `interactive` | `boolean` | `true` | Press and drag deformation. |
|
|
102
|
+
|
|
103
|
+
The default size is 48 dp high with 16 dp horizontal padding; override it with `style`. The
|
|
104
|
+
children are drawn *inside* the glass (clipped to it, deformed with it), so they are decorative:
|
|
105
|
+
don't put interactive elements in a button.
|
|
106
|
+
|
|
107
|
+
## `AndroidGlassToggle`
|
|
108
|
+
|
|
109
|
+
```tsx
|
|
110
|
+
<AndroidGlassToggle value={enabled} onValueChange={setEnabled} />
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
| Prop | Type | Default | Description |
|
|
114
|
+
| --- | --- | --- | --- |
|
|
115
|
+
| `value` | `boolean` | `false` | |
|
|
116
|
+
| `onValueChange` | `(value: boolean) => void` | — | Called on tap or when the thumb is dropped on the other side. |
|
|
117
|
+
| `accentColor` | `ColorValue` | iOS green | Track colour when on. |
|
|
118
|
+
| `trackColor` | `ColorValue` | translucent grey | Track colour when off. |
|
|
119
|
+
|
|
120
|
+
The track is 64 × 28 dp; the thumb turns into refracting glass and grows past it while dragged.
|
|
121
|
+
|
|
122
|
+
Use it controlled (`value` + `onValueChange`). A `value` prop only wins once JS has handled every
|
|
123
|
+
change made on the switch, so quick taps never make it flicker; if `onValueChange` doesn't take the
|
|
124
|
+
new value, the switch returns to `value`.
|
|
125
|
+
|
|
126
|
+
## `AndroidGlassSlider`
|
|
127
|
+
|
|
128
|
+
```tsx
|
|
129
|
+
<AndroidGlassSlider value={volume} maximumValue={100} onValueChange={setVolume} />
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
| Prop | Type | Default | Description |
|
|
133
|
+
| --- | --- | --- | --- |
|
|
134
|
+
| `value` | `number` | `0` | |
|
|
135
|
+
| `minimumValue` / `maximumValue` | `number` | `0` / `1` | |
|
|
136
|
+
| `onValueChange` | `(value: number) => void` | — | Called continuously while dragging. |
|
|
137
|
+
| `onSlidingComplete` | `(value: number) => void` | — | Called when the finger is lifted, or after a tap on the track. |
|
|
138
|
+
| `accentColor` | `ColorValue` | system blue | Filled part of the track. |
|
|
139
|
+
| `trackColor` | `ColorValue` | translucent grey | Unfilled part of the track. |
|
|
140
|
+
|
|
141
|
+
It stretches to the width of its parent and is 36 dp high by default.
|
|
142
|
+
|
|
143
|
+
Use it controlled (`value` + `onValueChange`). While a finger is on the slider it is driven
|
|
144
|
+
natively, and after that a `value` prop only wins once JS has handled every event the slider sent
|
|
145
|
+
(the handshake React Native's `TextInput` uses). So an older value never pulls the thumb back, even
|
|
146
|
+
on a slow JS thread, and a value you set in `onSlidingComplete` (a rounded one, say) still wins.
|
|
147
|
+
|
|
148
|
+
## `AndroidGlassBottomTabs` and `AndroidGlassTab`
|
|
149
|
+
|
|
150
|
+
Kyant's iOS 26 style tab bar: a glass capsule with a liquid selection droplet you can drag
|
|
151
|
+
between tabs. Under the droplet the tab content takes the accent colour and is magnified while
|
|
152
|
+
pressed.
|
|
153
|
+
|
|
154
|
+
```tsx
|
|
155
|
+
<AndroidGlassBottomTabs
|
|
156
|
+
selectedIndex={tab}
|
|
157
|
+
onTabSelected={setTab}
|
|
158
|
+
style={{ position: 'absolute', left: 24, right: 24, bottom: 32 }}>
|
|
159
|
+
<AndroidGlassTab label="Home" icon={<Ionicons name="home" size={24} />} />
|
|
160
|
+
<AndroidGlassTab label="Search" icon={<Ionicons name="search" size={24} />} />
|
|
161
|
+
<AndroidGlassTab label="Profile" icon={<Ionicons name="person" size={24} />} />
|
|
162
|
+
</AndroidGlassBottomTabs>
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
| Prop | Type | Default | Description |
|
|
166
|
+
| --- | --- | --- | --- |
|
|
167
|
+
| `selectedIndex` | `number` | `0` | |
|
|
168
|
+
| `onTabSelected` | `(index: number) => void` | — | Called on tap, or when the droplet is dropped on a tab. |
|
|
169
|
+
| `minimized` | `boolean` | `false` | Minimized look: shorter and narrower, labels faded out. Animated. See *Minimize on scroll*. |
|
|
170
|
+
| `onMinimizedChange` | `(minimized: boolean) => void` | — | Called with `false` when the user expands the minimized bar by touching it. |
|
|
171
|
+
| `accentColor` | `ColorValue` | system blue | Colour of the selected tab's content. |
|
|
172
|
+
| `containerColor` | `ColorValue` | translucent white | Colour of the glass bar. |
|
|
173
|
+
|
|
174
|
+
Each child is one tab (equal widths). `AndroidGlassTab` is an icon over a 12 sp label, but any
|
|
175
|
+
view works — as with buttons, the tabs are drawn inside the glass, so keep them decorative. The
|
|
176
|
+
bar is 64 dp high by default.
|
|
177
|
+
|
|
178
|
+
Use it controlled (`selectedIndex` + `onTabSelected`). A `selectedIndex` prop only wins once JS has
|
|
179
|
+
handled every selection made on the bar, so on quick taps or a busy JS thread the droplet never
|
|
180
|
+
jumps back to a tab the user already left. If `onTabSelected` doesn't take the new index, the
|
|
181
|
+
droplet returns to `selectedIndex`.
|
|
182
|
+
|
|
183
|
+
### Minimize on scroll
|
|
184
|
+
|
|
185
|
+
Like iOS 26 tab bars, the bar can shrink while the user scrolls down a list, and come back when
|
|
186
|
+
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. `useMinimizeOnScroll` does the
|
|
188
|
+
bookkeeping:
|
|
189
|
+
|
|
190
|
+
```tsx
|
|
191
|
+
const { minimized, setMinimized, onScroll } = useMinimizeOnScroll();
|
|
192
|
+
|
|
193
|
+
<ScrollView onScroll={onScroll} scrollEventThrottle={16}>…</ScrollView>
|
|
194
|
+
|
|
195
|
+
<AndroidGlassBottomTabs
|
|
196
|
+
selectedIndex={tab}
|
|
197
|
+
onTabSelected={setTab}
|
|
198
|
+
minimized={minimized}
|
|
199
|
+
onMinimizedChange={setMinimized}>
|
|
200
|
+
…
|
|
201
|
+
</AndroidGlassBottomTabs>
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
The scroll position is read in JS, where the list lives; only the resulting `minimized` flag goes
|
|
205
|
+
to the native side, where the animation runs. Any list that reports `onScroll` works (FlatList,
|
|
206
|
+
SectionList, FlashList…); if you already have an `onScroll`, call the hook's from it. The iOS and
|
|
207
|
+
web fallbacks don't minimize.
|
|
208
|
+
|
|
209
|
+
## Colours and dark mode
|
|
210
|
+
|
|
211
|
+
Component defaults (accent, track and container colours) follow the system dark mode setting,
|
|
212
|
+
like Kyant's samples. Pass the colour props to match your own theme.
|
|
213
|
+
|
|
214
|
+
## Gestures
|
|
215
|
+
|
|
216
|
+
The components look exactly like Kyant's samples, but take touches over a larger area:
|
|
217
|
+
|
|
218
|
+
- **Slider:** pressing anywhere on it moves the thumb under the finger (Kyant's sample only drags
|
|
219
|
+
the thumb and jumps on taps).
|
|
220
|
+
- **Tab bar:** a tap selects the tab under the finger, like Kyant's sample. A horizontal drag that
|
|
221
|
+
starts anywhere on the bar pulls the droplet under the finger and scrubs between tabs; releasing
|
|
222
|
+
selects the nearest tab. Dragging the droplet itself works as before.
|
|
223
|
+
- **Toggle:** the whole switch takes taps and drags, not only the thumb.
|
|
224
|
+
|
|
225
|
+
Toggles, sliders and the tab bar also claim horizontal drags: once a drag on them turns out to be
|
|
226
|
+
horizontal, a parent `ScrollView` no longer takes it over, and React Native's JS touch handlers
|
|
227
|
+
are told a native gesture started. Vertical drags still scroll.
|
|
228
|
+
|
|
229
|
+
## How it works
|
|
230
|
+
|
|
231
|
+
Each glass view is a React Native view whose first child is a Compose view drawing Kyant's
|
|
232
|
+
`drawBackdrop` modifier. Its backdrop is not a Compose layer but the Android view tree of the
|
|
233
|
+
window — i.e. your React Native screen:
|
|
234
|
+
|
|
235
|
+
1. Every container on the path from the window root to a glass view is drawn with the public
|
|
236
|
+
`View.draw()`, with glass views (and branches containing them) hidden for that call.
|
|
237
|
+
2. Every other subtree is recorded as a reference to its RenderNode, so when a list scrolls or a
|
|
238
|
+
view animates, the glass picks it up without re-sampling.
|
|
239
|
+
3. Glass views don't sample other glass views, except their own ancestors: a toggle on a glass
|
|
240
|
+
card sees the card. This rules out RenderNode cycles (glass A → glass B → glass A).
|
|
241
|
+
4. The capture is recorded once into a RenderNode with its own GPU layer, and only recorded again
|
|
242
|
+
when the glass moves, something scrolls or glass views come and go. Every glass layer of a view
|
|
243
|
+
(the tab bar has three) samples that same texture, so pressing or dragging only re-runs the
|
|
244
|
+
glass effects, not the capture.
|
|
245
|
+
|
|
246
|
+
## Limitations
|
|
247
|
+
|
|
248
|
+
- **Glass does not show other glass views** behind it, unless it sits inside them.
|
|
249
|
+
- Inside a container that holds a glass view, branches containing glass are drawn after their
|
|
250
|
+
siblings in the backdrop, so z-order can differ from the screen in that case.
|
|
251
|
+
- `SurfaceView`-based content (most video players, camera previews, some maps) is not part of the
|
|
252
|
+
view tree's drawing and shows up empty behind the glass. `TextureView` content works.
|
|
253
|
+
- A React Native `Modal` is a separate window, so glass inside it only sees the modal's content.
|
|
254
|
+
|
|
255
|
+
## Credits and licenses
|
|
256
|
+
|
|
257
|
+
This package is licensed under Apache-2.0. It contains code from
|
|
258
|
+
[Kyant0/AndroidLiquidGlass](https://github.com/Kyant0/AndroidLiquidGlass) (Apache-2.0) and
|
|
259
|
+
[QWEA0/Liquid-Glass-Android](https://github.com/QWEA0/Liquid-Glass-Android) (MIT); see
|
|
260
|
+
[THIRD_PARTY_NOTICES.md](./THIRD_PARTY_NOTICES.md).
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Third-party notices
|
|
2
|
+
|
|
3
|
+
This package includes code from the following projects.
|
|
4
|
+
|
|
5
|
+
## Kyant0/AndroidLiquidGlass (Backdrop)
|
|
6
|
+
|
|
7
|
+
- Source: https://github.com/Kyant0/AndroidLiquidGlass (commit 65ab177, library version 2.0.1)
|
|
8
|
+
- Location in this package:
|
|
9
|
+
- `android/src/main/java/expo/modules/androidglassview/backdrop/` — the Backdrop library
|
|
10
|
+
- `android/src/main/java/expo/modules/androidglassview/components/` — `LiquidButton`, `LiquidToggle`, `LiquidSlider`, `LiquidBottomTabs` (with `LiquidBottomTab`), `DampedDragAnimation`, `InteractiveHighlight` and `DragGestureInspector` from the Backdrop Catalog sample app
|
|
11
|
+
- License: Apache License, Version 2.0 — https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
- Copyright 2025 Kyant
|
|
13
|
+
- Changes to the library: package relocated from `com.kyant.backdrop`, Kotlin Multiplatform `expect`/`actual` merged into Android-only code, dependency on `io.github.kyant0:shapes` removed, Kotlin 2.1 compatible syntax (context parameters replaced by an explicit argument).
|
|
14
|
+
- Changes to the sample components: package relocated, made internal, configurable colours, `io.github.kyant0:shapes`' `Capsule` replaced by a rounded-corner capsule, Compose content slots replaced by draw callbacks (React Native children), sized by React Native, larger touch areas (the slider takes drags anywhere and moves the thumb under the finger, a horizontal drag anywhere on the tab bar scrubs the droplet between tabs, the whole toggle takes taps and drags), the tab bar can minimize (shorter and narrower, labels fading out), drag cancellation reported (a cancelled drag no longer toggles the switch), `DampedDragAnimation.moveToValue` added (moves without stretching the glass), `kotlin.time.Clock` replaced by `SystemClock`. Each modified file carries a notice.
|
|
15
|
+
|
|
16
|
+
## QWEA0/Liquid-Glass-Android (backdrop capture)
|
|
17
|
+
|
|
18
|
+
- Source: https://github.com/QWEA0/Liquid-Glass-Android (commit 73e2253, version 2.0.10)
|
|
19
|
+
- Location in this package: `android/src/main/java/expo/modules/androidglassview/capture/ViewBackdropCapture.kt` (adapted from `BackdropCapture.kt`)
|
|
20
|
+
- License: MIT
|
|
21
|
+
|
|
22
|
+
```
|
|
23
|
+
MIT License
|
|
24
|
+
|
|
25
|
+
Copyright (c) 2025-2026 pandadog
|
|
26
|
+
|
|
27
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
28
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
29
|
+
in the Software without restriction, including without limitation the rights
|
|
30
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
31
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
32
|
+
furnished to do so, subject to the following conditions:
|
|
33
|
+
|
|
34
|
+
The above copyright notice and this permission notice shall be included in all
|
|
35
|
+
copies or substantial portions of the Software.
|
|
36
|
+
|
|
37
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
38
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
39
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
40
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
41
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
42
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
43
|
+
SOFTWARE.
|
|
44
|
+
```
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
buildscript {
|
|
2
|
+
repositories {
|
|
3
|
+
mavenCentral()
|
|
4
|
+
}
|
|
5
|
+
dependencies {
|
|
6
|
+
classpath("org.jetbrains.kotlin.plugin.compose:org.jetbrains.kotlin.plugin.compose.gradle.plugin:${kotlinVersion}")
|
|
7
|
+
}
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
plugins {
|
|
11
|
+
id 'com.android.library'
|
|
12
|
+
id 'expo-module-gradle-plugin'
|
|
13
|
+
}
|
|
14
|
+
apply plugin: 'org.jetbrains.kotlin.plugin.compose'
|
|
15
|
+
|
|
16
|
+
group = 'expo.modules.androidglassview'
|
|
17
|
+
version = '0.1.0'
|
|
18
|
+
|
|
19
|
+
android {
|
|
20
|
+
namespace "expo.modules.androidglassview"
|
|
21
|
+
defaultConfig {
|
|
22
|
+
versionCode 1
|
|
23
|
+
versionName "0.1.0"
|
|
24
|
+
}
|
|
25
|
+
buildFeatures {
|
|
26
|
+
compose true
|
|
27
|
+
}
|
|
28
|
+
lintOptions {
|
|
29
|
+
abortOnError false
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
dependencies {
|
|
34
|
+
// NativeGestureUtil (claiming drags from scrolling parents). Version comes from the app.
|
|
35
|
+
implementation 'com.facebook.react:react-android'
|
|
36
|
+
// Same Compose version as @expo/ui for this Expo SDK, so apps using both resolve one runtime.
|
|
37
|
+
implementation 'androidx.compose.foundation:foundation-android:1.10.6'
|
|
38
|
+
implementation 'androidx.compose.ui:ui-android:1.10.6'
|
|
39
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
package expo.modules.androidglassview
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import android.graphics.Canvas
|
|
6
|
+
import android.view.View
|
|
7
|
+
import android.view.ViewGroup
|
|
8
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
9
|
+
import androidx.compose.runtime.Composable
|
|
10
|
+
import androidx.compose.runtime.getValue
|
|
11
|
+
import androidx.compose.runtime.mutableIntStateOf
|
|
12
|
+
import androidx.compose.runtime.mutableStateOf
|
|
13
|
+
import androidx.compose.runtime.setValue
|
|
14
|
+
import androidx.compose.ui.Modifier
|
|
15
|
+
import androidx.compose.ui.graphics.Color
|
|
16
|
+
import androidx.compose.ui.util.lerp
|
|
17
|
+
import expo.modules.androidglassview.components.LiquidBottomTabs
|
|
18
|
+
import expo.modules.androidglassview.components.TabsFrame
|
|
19
|
+
import expo.modules.kotlin.AppContext
|
|
20
|
+
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Kyant's LiquidBottomTabs: a glass tab bar with a draggable liquid selection droplet. The React
|
|
24
|
+
* children are the tabs (one child per tab, equal widths); they are drawn inside the glass, and
|
|
25
|
+
* again in the accent colour under the droplet.
|
|
26
|
+
*/
|
|
27
|
+
@SuppressLint("ViewConstructor")
|
|
28
|
+
class AndroidGlassBottomTabs(context: Context, appContext: AppContext) : GlassHostView(context, appContext) {
|
|
29
|
+
|
|
30
|
+
override val drawsReactChildrenInCompose: Boolean = true
|
|
31
|
+
override val claimsHorizontalDrags: Boolean = true
|
|
32
|
+
|
|
33
|
+
internal var selectedIndex by mutableIntStateOf(0)
|
|
34
|
+
private set
|
|
35
|
+
internal var tabsCount by mutableIntStateOf(1)
|
|
36
|
+
internal var accentColor by mutableStateOf<Color?>(null)
|
|
37
|
+
internal var containerColor by mutableStateOf<Color?>(null)
|
|
38
|
+
|
|
39
|
+
/** The `selectedIndex` prop; it only wins once JS has handled every selection made on the bar. */
|
|
40
|
+
internal val selectedIndexProp = ControlledProp(0)
|
|
41
|
+
|
|
42
|
+
internal var minimized by mutableStateOf(false)
|
|
43
|
+
private set
|
|
44
|
+
private var minimizedProp = false
|
|
45
|
+
|
|
46
|
+
private val onTabSelected by EventDispatcher()
|
|
47
|
+
private val onMinimizedChange by EventDispatcher()
|
|
48
|
+
private val selectedIndexProvider: () -> Int = { selectedIndex }
|
|
49
|
+
private val minimizedProvider: () -> Boolean = { minimized }
|
|
50
|
+
|
|
51
|
+
// Touching a minimized bar brings it back, like on iOS; JS is told so it can stay in sync.
|
|
52
|
+
private val expand: () -> Unit = {
|
|
53
|
+
if (minimized) {
|
|
54
|
+
minimized = false
|
|
55
|
+
onMinimizedChange(mapOf("minimized" to false))
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Called once all props of an update are set. */
|
|
60
|
+
internal fun applyProps() {
|
|
61
|
+
if (selectedIndexProp.isCurrent) selectedIndex = selectedIndexProp.value
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Applies the `minimized` prop. Only a change counts: the bar also expands by itself when
|
|
66
|
+
* touched, and then stays expanded until JS minimizes it again.
|
|
67
|
+
*/
|
|
68
|
+
internal fun setMinimizedProp(value: Boolean) {
|
|
69
|
+
if (value != minimizedProp) {
|
|
70
|
+
minimizedProp = value
|
|
71
|
+
minimized = value
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Composable
|
|
76
|
+
override fun GlassContent() {
|
|
77
|
+
LiquidBottomTabs(
|
|
78
|
+
selectedTabIndex = selectedIndexProvider,
|
|
79
|
+
onTabSelected = { index ->
|
|
80
|
+
// Selections that came from the `selectedIndex` prop are not echoed back to JS.
|
|
81
|
+
if (index != selectedIndex) {
|
|
82
|
+
selectedIndex = index
|
|
83
|
+
onTabSelected(mapOf("index" to index, "eventCount" to selectedIndexProp.nextEventCount()))
|
|
84
|
+
}
|
|
85
|
+
},
|
|
86
|
+
backdrop = backdrop,
|
|
87
|
+
tabsCount = tabsCount.coerceAtLeast(1),
|
|
88
|
+
drawTabs = { origin, frame, tint, scale ->
|
|
89
|
+
// Reading the generation subscribes this draw to changes of the React children.
|
|
90
|
+
if (reactChildrenGeneration >= 0) {
|
|
91
|
+
drawReactLayer(origin, tint) { canvas -> drawTabsInto(canvas, frame, scale) }
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
modifier = Modifier.fillMaxSize(),
|
|
95
|
+
minimized = minimizedProvider,
|
|
96
|
+
onExpand = expand,
|
|
97
|
+
accentColor = accentColor,
|
|
98
|
+
containerColor = containerColor
|
|
99
|
+
)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Draws the tabs in [frame]'s slots. React Native lays them out for the expanded bar, so while
|
|
104
|
+
* the bar minimizes each tab follows its narrower slot, its first child (the icon) moves to the
|
|
105
|
+
* bar's centre and its other children (the label) fade out. [scale] magnifies each tab.
|
|
106
|
+
*/
|
|
107
|
+
private fun drawTabsInto(canvas: Canvas, frame: TabsFrame, scale: Float) {
|
|
108
|
+
val progress = frame.minimizeProgress
|
|
109
|
+
val labelAlpha = 1f - (progress / LABEL_FADE_END).coerceIn(0f, 1f)
|
|
110
|
+
for (i in 0 until reactChildCount) {
|
|
111
|
+
val tab = getReactChildAt(i) ?: continue
|
|
112
|
+
if (tab.visibility != View.VISIBLE) continue
|
|
113
|
+
val left = (tab.left - scrollX).toFloat()
|
|
114
|
+
val top = (tab.top - scrollY).toFloat()
|
|
115
|
+
val width = tab.width.toFloat()
|
|
116
|
+
val height = tab.height.toFloat()
|
|
117
|
+
val icon = (tab as? ViewGroup)?.takeIf { it.childCount > 0 }?.getChildAt(0)
|
|
118
|
+
val iconCenterY = if (icon != null) icon.top + icon.height / 2f else height / 2f
|
|
119
|
+
val centerX = left + width / 2f
|
|
120
|
+
val save = canvas.save()
|
|
121
|
+
canvas.translate(
|
|
122
|
+
left + frame.mapX(centerX) - centerX,
|
|
123
|
+
top + progress * (frame.centerY - (top + iconCenterY))
|
|
124
|
+
)
|
|
125
|
+
val matrix = tab.matrix
|
|
126
|
+
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
127
|
+
if (scale != 1f) canvas.scale(scale, scale, width / 2f, lerp(height / 2f, iconCenterY, progress))
|
|
128
|
+
if (tab is ViewGroup && labelAlpha < 1f) {
|
|
129
|
+
drawFadingChildren(canvas, tab, labelAlpha)
|
|
130
|
+
} else {
|
|
131
|
+
val alpha = tab.alpha
|
|
132
|
+
if (alpha < 1f) canvas.saveLayerAlpha(0f, 0f, width, height, (alpha * 255f).toInt())
|
|
133
|
+
tab.draw(canvas)
|
|
134
|
+
}
|
|
135
|
+
canvas.restoreToCount(save)
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/** Draws [tab]'s children one by one: the first as is, the others at [labelAlpha]. */
|
|
140
|
+
private fun drawFadingChildren(canvas: Canvas, tab: ViewGroup, labelAlpha: Float) {
|
|
141
|
+
for (j in 0 until tab.childCount) {
|
|
142
|
+
val child = tab.getChildAt(j)
|
|
143
|
+
if (child.visibility != View.VISIBLE) continue
|
|
144
|
+
val alpha = tab.alpha * child.alpha * if (j == 0) 1f else labelAlpha
|
|
145
|
+
if (alpha <= 0f) continue
|
|
146
|
+
val save = canvas.save()
|
|
147
|
+
canvas.translate((child.left - tab.scrollX).toFloat(), (child.top - tab.scrollY).toFloat())
|
|
148
|
+
val matrix = child.matrix
|
|
149
|
+
if (!matrix.isIdentity) canvas.concat(matrix)
|
|
150
|
+
if (alpha < 1f) {
|
|
151
|
+
canvas.saveLayerAlpha(0f, 0f, child.width.toFloat(), child.height.toFloat(), (alpha * 255f).toInt())
|
|
152
|
+
}
|
|
153
|
+
child.draw(canvas)
|
|
154
|
+
canvas.restoreToCount(save)
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
companion object {
|
|
159
|
+
/** Minimize progress at which the labels are gone. */
|
|
160
|
+
private const val LABEL_FADE_END = 0.4f
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
package expo.modules.androidglassview
|
|
2
|
+
|
|
3
|
+
import android.annotation.SuppressLint
|
|
4
|
+
import android.content.Context
|
|
5
|
+
import androidx.compose.foundation.layout.fillMaxSize
|
|
6
|
+
import androidx.compose.runtime.Composable
|
|
7
|
+
import androidx.compose.runtime.getValue
|
|
8
|
+
import androidx.compose.runtime.mutableStateOf
|
|
9
|
+
import androidx.compose.runtime.setValue
|
|
10
|
+
import androidx.compose.ui.Modifier
|
|
11
|
+
import expo.modules.androidglassview.components.LiquidButton
|
|
12
|
+
import expo.modules.kotlin.AppContext
|
|
13
|
+
import expo.modules.kotlin.viewevent.EventDispatcher
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Kyant's LiquidButton. The React children (label, icon, …) are drawn inside the glass, so they
|
|
17
|
+
* follow its press and drag deformation.
|
|
18
|
+
*/
|
|
19
|
+
@SuppressLint("ViewConstructor")
|
|
20
|
+
class AndroidGlassButton(context: Context, appContext: AppContext) : GlassHostView(context, appContext) {
|
|
21
|
+
|
|
22
|
+
override val drawsReactChildrenInCompose: Boolean = true
|
|
23
|
+
|
|
24
|
+
internal val glassState = GlassState().apply { cornerRadius = DEFAULT_CORNER_RADIUS }
|
|
25
|
+
internal var interactive by mutableStateOf(true)
|
|
26
|
+
|
|
27
|
+
private val onPress by EventDispatcher()
|
|
28
|
+
|
|
29
|
+
@Composable
|
|
30
|
+
override fun GlassContent() {
|
|
31
|
+
LiquidButton(
|
|
32
|
+
onClick = { onPress(emptyMap<String, Any>()) },
|
|
33
|
+
backdrop = backdrop,
|
|
34
|
+
state = glassState,
|
|
35
|
+
isInteractive = interactive,
|
|
36
|
+
drawContent = { drawReactChildren(this@AndroidGlassButton) },
|
|
37
|
+
modifier = Modifier.fillMaxSize()
|
|
38
|
+
)
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
companion object {
|
|
42
|
+
/** Capsule: the lens clamps corner radii to half of the shorter side. */
|
|
43
|
+
const val DEFAULT_CORNER_RADIUS = 999f
|
|
44
|
+
}
|
|
45
|
+
}
|