@onekeyfe/react-native-bottom-tabs 0.0.0-stage → 6.7.0-10

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.
Files changed (78) hide show
  1. package/LICENSE +46 -0
  2. package/README.md +94 -2
  3. package/android/build.gradle +119 -0
  4. package/android/gradle.properties +4 -0
  5. package/android/src/main/AndroidManifest.xml +3 -0
  6. package/android/src/main/AndroidManifestNew.xml +2 -0
  7. package/android/src/main/java/com/onekey/bottomtabs/BottomBarBlurRenderer.kt +92 -0
  8. package/android/src/main/java/com/onekey/bottomtabs/BottomTabsPackage.kt +16 -0
  9. package/android/src/main/java/com/onekey/bottomtabs/BottomTabsView.kt +1558 -0
  10. package/android/src/main/java/com/onekey/bottomtabs/BottomTabsViewManager.kt +220 -0
  11. package/android/src/main/java/com/onekey/bottomtabs/FloatingTabBarStyle.kt +50 -0
  12. package/android/src/main/java/com/onekey/bottomtabs/ImageSource.kt +86 -0
  13. package/android/src/main/java/com/onekey/bottomtabs/TabInfo.kt +13 -0
  14. package/android/src/main/java/com/onekey/bottomtabs/Utils.kt +31 -0
  15. package/android/src/main/java/com/onekey/bottomtabs/events/OnNativeLayoutEvent.kt +20 -0
  16. package/android/src/main/java/com/onekey/bottomtabs/events/OnTabBarMeasuredEvent.kt +19 -0
  17. package/android/src/main/java/com/onekey/bottomtabs/events/PageSelectedEvent.kt +21 -0
  18. package/android/src/main/java/com/onekey/bottomtabs/events/TabDoublePressEvent.kt +19 -0
  19. package/common/cpp/react/renderer/components/RNBottomTabs/RNBottomTabsViewComponentDescriptor.h +32 -0
  20. package/common/cpp/react/renderer/components/RNBottomTabs/RNBottomTabsViewShadowNode.cpp +18 -0
  21. package/common/cpp/react/renderer/components/RNBottomTabs/RNBottomTabsViewShadowNode.h +35 -0
  22. package/common/cpp/react/renderer/components/RNBottomTabs/RNBottomTabsViewState.cpp +15 -0
  23. package/common/cpp/react/renderer/components/RNBottomTabs/RNBottomTabsViewState.h +25 -0
  24. package/docs/SPEC.md +168 -0
  25. package/ios/Extensions.swift +46 -0
  26. package/ios/RCTBottomAccessoryComponentView.h +12 -0
  27. package/ios/RCTBottomAccessoryComponentView.mm +67 -0
  28. package/ios/RCTBottomAccessoryContainerView.swift +51 -0
  29. package/ios/RCTBottomTabsComponentView.h +12 -0
  30. package/ios/RCTBottomTabsComponentView.mm +338 -0
  31. package/ios/RCTBottomTabsContainerView.swift +777 -0
  32. package/ios/RCTBottomTabsLog.h +7 -0
  33. package/ios/RCTBottomTabsLog.m +32 -0
  34. package/ios/SVG/CoreSVG.h +13 -0
  35. package/ios/SVG/CoreSVG.mm +177 -0
  36. package/ios/SVG/SvgDecoder.h +10 -0
  37. package/ios/SVG/SvgDecoder.mm +32 -0
  38. package/ios/TabBarFontSize.swift +55 -0
  39. package/lib/module/BottomAccessoryView.js +45 -0
  40. package/lib/module/BottomAccessoryViewNativeComponent.ts +27 -0
  41. package/lib/module/BottomTabs.js +325 -0
  42. package/lib/module/BottomTabsNativeComponent.ts +70 -0
  43. package/lib/module/DelayedFreeze.js +31 -0
  44. package/lib/module/NativeSVGDecoder.js +5 -0
  45. package/lib/module/SceneMap.js +28 -0
  46. package/lib/module/codegen-types.d.js +2 -0
  47. package/lib/module/index.js +20 -0
  48. package/lib/module/package.json +1 -0
  49. package/lib/module/types.js +4 -0
  50. package/lib/module/utils/BottomTabBarHeightContext.js +5 -0
  51. package/lib/module/utils/useBottomTabBarHeight.js +12 -0
  52. package/lib/typescript/package.json +1 -0
  53. package/lib/typescript/src/BottomAccessoryView.d.ts +8 -0
  54. package/lib/typescript/src/BottomAccessoryViewNativeComponent.d.ts +16 -0
  55. package/lib/typescript/src/BottomTabs.d.ts +209 -0
  56. package/lib/typescript/src/BottomTabsNativeComponent.d.ts +59 -0
  57. package/lib/typescript/src/DelayedFreeze.d.ts +9 -0
  58. package/lib/typescript/src/NativeSVGDecoder.d.ts +6 -0
  59. package/lib/typescript/src/SceneMap.d.ts +10 -0
  60. package/lib/typescript/src/index.d.ts +16 -0
  61. package/lib/typescript/src/types.d.ts +29 -0
  62. package/lib/typescript/src/utils/BottomTabBarHeightContext.d.ts +3 -0
  63. package/lib/typescript/src/utils/useBottomTabBarHeight.d.ts +2 -0
  64. package/package.json +117 -4
  65. package/react-native-bottom-tabs.podspec +36 -0
  66. package/react-native.config.js +13 -0
  67. package/src/BottomAccessoryView.tsx +58 -0
  68. package/src/BottomAccessoryViewNativeComponent.ts +27 -0
  69. package/src/BottomTabs.tsx +559 -0
  70. package/src/BottomTabsNativeComponent.ts +70 -0
  71. package/src/DelayedFreeze.tsx +33 -0
  72. package/src/NativeSVGDecoder.ts +5 -0
  73. package/src/SceneMap.tsx +34 -0
  74. package/src/codegen-types.d.ts +28 -0
  75. package/src/index.tsx +18 -0
  76. package/src/types.ts +31 -0
  77. package/src/utils/BottomTabBarHeightContext.ts +5 -0
  78. package/src/utils/useBottomTabBarHeight.ts +15 -0
package/LICENSE ADDED
@@ -0,0 +1,46 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Callstack
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
21
+
22
+ ---
23
+
24
+ The Expo-derived ResourceIdHelper code in android/src/main/java/com/onekey/bottomtabs/ImageSource.kt retains:
25
+
26
+ The MIT License (MIT)
27
+
28
+ Copyright (c) 2015-present 650 Industries, Inc. (aka Expo)
29
+
30
+ Permission is hereby granted, free of charge, to any person obtaining a copy
31
+ of this software and associated documentation files (the "Software"), to deal
32
+ in the Software without restriction, including without limitation the rights
33
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
34
+ copies of the Software, and to permit persons to whom the Software is
35
+ furnished to do so, subject to the following conditions:
36
+
37
+ The above copyright notice and this permission notice shall be included in all
38
+ copies or substantial portions of the Software.
39
+
40
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
41
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
42
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
43
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
44
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
45
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
46
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # @onekeyfe/react-native-bottom-tabs
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Native bottom-tab navigation for OneKey React Native applications on iOS and
4
+ Android. The controlled React component receives route state from the caller
5
+ and renders scenes through the application's supplied renderer.
6
+
7
+ ## Installation and usage
8
+
9
+ ```sh
10
+ yarn add @onekeyfe/react-native-bottom-tabs
11
+ ```
12
+
13
+ Install the application's iOS pods and rebuild the native application to register
14
+ the bottom tabs. The application owns route definitions and selection state.
15
+
16
+ ```tsx
17
+ import { useState } from 'react';
18
+ import { Text } from 'react-native';
19
+ import BottomTabs from '@onekeyfe/react-native-bottom-tabs';
20
+
21
+ const routes = [{ key: 'home', title: 'Home' }, { key: 'settings', title: 'Settings' }];
22
+
23
+ function Tabs() {
24
+ const [index, setIndex] = useState(0);
25
+ return (
26
+ <BottomTabs
27
+ navigationState={{ index, routes }}
28
+ onIndexChange={setIndex}
29
+ renderScene={({ route }) => <Text>{route.title}</Text>}
30
+ />
31
+ );
32
+ }
33
+ ```
34
+
35
+ Earlier releases were published as `@onekeyfe/react-native-tab-view`, where
36
+ the default export was `TabView` and `onTabLongPress` existed.
37
+
38
+ ## State, scenes and platform options
39
+
40
+ `navigationState` contains the selected index and keyed routes. `onIndexChange`
41
+ reports requested tab changes; update state in the caller. Route metadata can
42
+ supply labels, badges and icons. `SceneMap` builds a renderer from stable scene
43
+ components; `useBottomTabBarHeight` and `BottomTabBarHeightContext` expose tab-bar
44
+ height to content under the provider.
45
+
46
+ The default export is `BottomTabs`; `AppleIcon` and `TabRole` are exported types.
47
+ Some appearance and interaction options are platform-specific, including Apple
48
+ symbols and newer iOS tab-bar presentation. Check those options against the
49
+ consumer's supported OS versions rather than assuming identical native layouts.
50
+
51
+ On Android, `androidBottomBlurEnabled` controls live background blur, translucent
52
+ tint, and a gradient above the native bar. It defaults to enabled on Android 16+
53
+ (API 36); pass `false` to disable it or `true` to enable it on Android 12–15.
54
+ Earlier Android versions retain the standard bar. It is ignored on iOS and with
55
+ a custom `tabBar`. When enabled, scenes extend behind the bar: use
56
+ `useBottomTabBarHeight()` as scroll-content bottom padding so the last row can
57
+ scroll above it. `tabBarStyle.backgroundColor` sets the surface tint.
58
+
59
+ See [src/BottomTabs.tsx](src/BottomTabs.tsx) for component props and
60
+ [src/types.ts](src/types.ts) for route definitions.
61
+
62
+ See [docs/SPEC.md](docs/SPEC.md) for native touch-selection contracts and
63
+ acceptance boundaries.
64
+
65
+ ## Upstream attribution
66
+
67
+ First, a sincere thank-you to Oskar Kwaśniewski and the
68
+ `react-native-bottom-tabs` maintainers for their excellent work 🙏
69
+
70
+ This package is built on, and inspired by,
71
+ [okwasniewski/react-native-bottom-tabs](https://github.com/okwasniewski/react-native-bottom-tabs).
72
+
73
+ Our original plan was to keep our customizations as patches on top of upstream
74
+ `react-native-bottom-tabs`.
75
+
76
+ As our product requirements evolved, the scope of those changes outgrew what we
77
+ could reasonably maintain as an upstream patch set. We regret that we were
78
+ unable to keep this work in patch form.
79
+
80
+ As the gap grew, we ultimately forked `react-native-bottom-tabs` to keep
81
+ development and delivery stable.
82
+
83
+ ## Upstream Project
84
+
85
+ - Repository: [okwasniewski/react-native-bottom-tabs](https://github.com/okwasniewski/react-native-bottom-tabs)
86
+ - License: MIT
87
+
88
+ ## Notes
89
+
90
+ - This fork includes OneKey-specific adaptations for our product requirements.
91
+ - If you are looking for original behavior and full documentation, please refer
92
+ to the upstream repository.
93
+
94
+ Thank you again to Oskar Kwaśniewski and everyone who contributes to
95
+ `react-native-bottom-tabs` 💙
@@ -0,0 +1,119 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['BottomTabs_' + name]
4
+ }
5
+
6
+ def kotlin_version = rootProject.ext.has("kotlinVersion") ? rootProject.ext.get("kotlinVersion") : project.properties["BottomTabs_kotlinVersion"]
7
+
8
+ repositories {
9
+ google()
10
+ mavenCentral()
11
+ }
12
+
13
+ dependencies {
14
+ classpath "com.android.tools.build:gradle:8.7.2"
15
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
16
+ }
17
+ }
18
+
19
+ def isNewArchitectureEnabled() {
20
+ return true
21
+ }
22
+
23
+ def reactNativeArchitectures() {
24
+ def value = rootProject.getProperties().get("reactNativeArchitectures")
25
+ return value ? value.split(",") : ["armeabi-v7a", "x86", "x86_64", "arm64-v8a"]
26
+ }
27
+
28
+ apply plugin: "com.android.library"
29
+ apply plugin: "kotlin-android"
30
+
31
+ if (isNewArchitectureEnabled()) {
32
+ apply plugin: "com.facebook.react"
33
+ }
34
+
35
+ def getExtOrIntegerDefault(name) {
36
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["BottomTabs_" + name]).toInteger()
37
+ }
38
+
39
+ def supportsNamespace() {
40
+ def parsed = com.android.Version.ANDROID_GRADLE_PLUGIN_VERSION.tokenize('.')
41
+ def major = parsed[0].toInteger()
42
+ def minor = parsed[1].toInteger()
43
+ return (major == 7 && minor >= 3) || major >= 8
44
+ }
45
+
46
+ android {
47
+ if (supportsNamespace()) {
48
+ namespace "com.onekey.bottomtabs"
49
+
50
+ sourceSets {
51
+ main {
52
+ manifest.srcFile "src/main/AndroidManifestNew.xml"
53
+ }
54
+ }
55
+ }
56
+
57
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
58
+
59
+ defaultConfig {
60
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
61
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
62
+ buildConfigField "boolean", "IS_NEW_ARCHITECTURE_ENABLED", isNewArchitectureEnabled().toString()
63
+ }
64
+
65
+ buildFeatures {
66
+ buildConfig true
67
+ }
68
+
69
+ buildTypes {
70
+ release {
71
+ minifyEnabled false
72
+ }
73
+ }
74
+
75
+ lintOptions {
76
+ disable "GradleCompatible"
77
+ }
78
+
79
+ compileOptions {
80
+ sourceCompatibility JavaVersion.VERSION_1_8
81
+ targetCompatibility JavaVersion.VERSION_1_8
82
+ }
83
+
84
+ sourceSets {
85
+ main {
86
+ java.srcDirs += [
87
+ // Codegen specs
88
+ "generated/java",
89
+ "generated/jni"
90
+ ]
91
+ }
92
+ }
93
+ }
94
+
95
+ repositories {
96
+ mavenCentral()
97
+ google()
98
+ }
99
+
100
+ def kotlin_version = getExtOrDefault("kotlinVersion")
101
+ def COIL_VERSION = "3.0.2"
102
+
103
+ dependencies {
104
+ implementation "com.facebook.react:react-android"
105
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
106
+ implementation 'com.google.android.material:material:1.14.0-alpha05'
107
+
108
+ implementation("io.coil-kt.coil3:coil:${COIL_VERSION}")
109
+ implementation("io.coil-kt.coil3:coil-network-okhttp:${COIL_VERSION}")
110
+ implementation("io.coil-kt.coil3:coil-svg:${COIL_VERSION}")
111
+ }
112
+
113
+ if (isNewArchitectureEnabled()) {
114
+ react {
115
+ jsRootDir = file("../src/")
116
+ libraryName = "RNBottomTabs"
117
+ codegenJavaPackageName = "com.onekey.bottomtabs"
118
+ }
119
+ }
@@ -0,0 +1,4 @@
1
+ BottomTabs_kotlinVersion=1.9.24
2
+ BottomTabs_minSdkVersion=24
3
+ BottomTabs_targetSdkVersion=35
4
+ BottomTabs_compileSdkVersion=35
@@ -0,0 +1,3 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android"
2
+ package="com.onekey.bottomtabs">
3
+ </manifest>
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,92 @@
1
+ package com.onekey.bottomtabs
2
+
3
+ import android.graphics.BlendMode
4
+ import android.graphics.Canvas
5
+ import android.graphics.Color
6
+ import android.graphics.LinearGradient
7
+ import android.graphics.Paint
8
+ import android.graphics.RenderEffect
9
+ import android.graphics.RenderNode
10
+ import android.graphics.Shader
11
+ import androidx.annotation.RequiresApi
12
+ import kotlin.math.ceil
13
+ import kotlin.math.max
14
+
15
+ /** A GPU-only backdrop. The source callback must draw scenes, never this overlay. */
16
+ @RequiresApi(31)
17
+ internal class BottomBarBlurRenderer(private val density: Float) {
18
+ private val node = RenderNode("TabBarBackdrop")
19
+ private val tintPaint = Paint()
20
+ private val maskPaint = Paint().apply { blendMode = BlendMode.DST_IN }
21
+ private var lastWidth = 0
22
+ private var lastBarTop = -1
23
+ private var lastBottom = 0
24
+ private var lastTint = Color.TRANSPARENT
25
+ private var fadeTop = 0f
26
+ private var sampleTop = 0f
27
+
28
+ init {
29
+ node.setRenderEffect(RenderEffect.createBlurEffect(
30
+ 20f * density / SCALE,
31
+ 20f * density / SCALE,
32
+ Shader.TileMode.CLAMP,
33
+ ))
34
+ }
35
+
36
+ fun draw(
37
+ canvas: Canvas,
38
+ width: Int,
39
+ barTop: Int,
40
+ bottom: Int,
41
+ tint: Int,
42
+ drawScenes: (Canvas) -> Unit,
43
+ ) {
44
+ if (!canvas.isHardwareAccelerated || width <= 0 || bottom <= barTop) return
45
+
46
+ if (width != lastWidth || barTop != lastBarTop || bottom != lastBottom || tint != lastTint) {
47
+ fadeTop = max(0f, barTop - 24f * density)
48
+ sampleTop = max(0f, fadeTop - 40f * density)
49
+ node.setPosition(0, 0, ceil(width / SCALE).toInt(), ceil((bottom - sampleTop) / SCALE).toInt())
50
+ maskPaint.shader = LinearGradient(
51
+ 0f, fadeTop, 0f, barTop.toFloat(),
52
+ Color.TRANSPARENT, Color.WHITE, Shader.TileMode.CLAMP,
53
+ )
54
+ val surface = (tint and 0x00ffffff) or (minOf(Color.alpha(tint), 199) shl 24)
55
+ tintPaint.color = surface
56
+ lastWidth = width
57
+ lastBarTop = barTop
58
+ lastBottom = bottom
59
+ lastTint = tint
60
+ }
61
+
62
+ val recording = node.beginRecording()
63
+ try {
64
+ // Reuse child View display lists. No bitmap capture or full-screen blur.
65
+ recording.scale(1f / SCALE, 1f / SCALE)
66
+ recording.translate(0f, -sampleTop)
67
+ recording.drawColor(tint or (0xff shl 24))
68
+ drawScenes(recording)
69
+ } finally {
70
+ node.endRecording()
71
+ }
72
+
73
+ val layer = canvas.saveLayer(0f, fadeTop, width.toFloat(), bottom.toFloat(), null)
74
+ val transform = canvas.save()
75
+ canvas.translate(0f, sampleTop)
76
+ canvas.scale(SCALE, SCALE)
77
+ canvas.drawRenderNode(node)
78
+ canvas.restoreToCount(transform)
79
+ canvas.drawRect(0f, fadeTop, width.toFloat(), bottom.toFloat(), tintPaint)
80
+ // Fade the combined blur and tint, keeping the transition free of a hard seam.
81
+ canvas.drawRect(0f, fadeTop, width.toFloat(), bottom.toFloat(), maskPaint)
82
+ canvas.restoreToCount(layer)
83
+ }
84
+
85
+ fun release() {
86
+ node.discardDisplayList()
87
+ }
88
+
89
+ private companion object {
90
+ const val SCALE = 4f
91
+ }
92
+ }
@@ -0,0 +1,16 @@
1
+ package com.onekey.bottomtabs
2
+
3
+ import com.facebook.react.ReactPackage
4
+ import com.facebook.react.bridge.NativeModule
5
+ import com.facebook.react.bridge.ReactApplicationContext
6
+ import com.facebook.react.uimanager.ViewManager
7
+
8
+ class BottomTabsPackage : ReactPackage {
9
+ override fun createViewManagers(reactContext: ReactApplicationContext): List<ViewManager<*, *>> {
10
+ return listOf(BottomTabsViewManager(reactContext))
11
+ }
12
+
13
+ override fun createNativeModules(reactContext: ReactApplicationContext): List<NativeModule> {
14
+ return emptyList()
15
+ }
16
+ }