react-native-platform-components 0.0.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.
Files changed (63) hide show
  1. package/LICENSE +20 -0
  2. package/PlatformComponents.podspec +20 -0
  3. package/README.md +233 -0
  4. package/android/build.gradle +78 -0
  5. package/android/gradle.properties +5 -0
  6. package/android/src/main/AndroidManifest.xml +2 -0
  7. package/android/src/main/java/com/platformcomponents/DateConstraints.kt +83 -0
  8. package/android/src/main/java/com/platformcomponents/Helper.kt +27 -0
  9. package/android/src/main/java/com/platformcomponents/PCDatePickerView.kt +684 -0
  10. package/android/src/main/java/com/platformcomponents/PCDatePickerViewManager.kt +149 -0
  11. package/android/src/main/java/com/platformcomponents/PCMaterialMode.kt +16 -0
  12. package/android/src/main/java/com/platformcomponents/PCSelectionMenuView.kt +410 -0
  13. package/android/src/main/java/com/platformcomponents/PCSelectionMenuViewManager.kt +114 -0
  14. package/android/src/main/java/com/platformcomponents/PlatformComponentsPackage.kt +22 -0
  15. package/ios/PCDatePicker.h +11 -0
  16. package/ios/PCDatePicker.mm +248 -0
  17. package/ios/PCDatePickerView.swift +405 -0
  18. package/ios/PCSelectionMenu.h +10 -0
  19. package/ios/PCSelectionMenu.mm +182 -0
  20. package/ios/PCSelectionMenu.swift +434 -0
  21. package/lib/module/DatePicker.js +74 -0
  22. package/lib/module/DatePicker.js.map +1 -0
  23. package/lib/module/DatePickerNativeComponent.ts +68 -0
  24. package/lib/module/SelectionMenu.js +79 -0
  25. package/lib/module/SelectionMenu.js.map +1 -0
  26. package/lib/module/SelectionMenu.web.js +57 -0
  27. package/lib/module/SelectionMenu.web.js.map +1 -0
  28. package/lib/module/SelectionMenuNativeComponent.ts +106 -0
  29. package/lib/module/index.js +6 -0
  30. package/lib/module/index.js.map +1 -0
  31. package/lib/module/package.json +1 -0
  32. package/lib/module/sharedTypes.js +4 -0
  33. package/lib/module/sharedTypes.js.map +1 -0
  34. package/lib/typescript/package.json +1 -0
  35. package/lib/typescript/src/DatePicker.d.ts +38 -0
  36. package/lib/typescript/src/DatePicker.d.ts.map +1 -0
  37. package/lib/typescript/src/DatePickerNativeComponent.d.ts +53 -0
  38. package/lib/typescript/src/DatePickerNativeComponent.d.ts.map +1 -0
  39. package/lib/typescript/src/SelectionMenu.d.ts +50 -0
  40. package/lib/typescript/src/SelectionMenu.d.ts.map +1 -0
  41. package/lib/typescript/src/SelectionMenu.web.d.ts +19 -0
  42. package/lib/typescript/src/SelectionMenu.web.d.ts.map +1 -0
  43. package/lib/typescript/src/SelectionMenuNativeComponent.d.ts +85 -0
  44. package/lib/typescript/src/SelectionMenuNativeComponent.d.ts.map +1 -0
  45. package/lib/typescript/src/index.d.ts +4 -0
  46. package/lib/typescript/src/index.d.ts.map +1 -0
  47. package/lib/typescript/src/sharedTypes.d.ts +10 -0
  48. package/lib/typescript/src/sharedTypes.d.ts.map +1 -0
  49. package/package.json +178 -0
  50. package/shared/PCDatePickerComponentDescriptors-custom.h +52 -0
  51. package/shared/PCDatePickerShadowNode-custom.cpp +1 -0
  52. package/shared/PCDatePickerShadowNode-custom.h +27 -0
  53. package/shared/PCDatePickerState-custom.h +13 -0
  54. package/shared/PCSelectionMenuComponentDescriptors-custom.h +25 -0
  55. package/shared/PCSelectionMenuShadowNode-custom.cpp +36 -0
  56. package/shared/PCSelectionMenuShadowNode-custom.h +46 -0
  57. package/src/DatePicker.tsx +146 -0
  58. package/src/DatePickerNativeComponent.ts +68 -0
  59. package/src/SelectionMenu.tsx +170 -0
  60. package/src/SelectionMenu.web.tsx +93 -0
  61. package/src/SelectionMenuNativeComponent.ts +106 -0
  62. package/src/index.tsx +3 -0
  63. package/src/sharedTypes.ts +14 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Andrew Tosh
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.
@@ -0,0 +1,20 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "PlatformComponents"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/BearPeak-Technology-Group/react-native-platform-components.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = ["ios/**/*.{h,m,mm,swift,cpp}", "shared/**/*.{h,m,mm,swift,cpp}"]
17
+ s.private_header_files = ["ios/**/*.h", "shared/**/*.h"]
18
+
19
+ install_modules_dependencies(s)
20
+ end
package/README.md ADDED
@@ -0,0 +1,233 @@
1
+ # react-native-platform-components
2
+
3
+ High-quality **native UI components for React Native**, implemented with platform-first APIs and exposed through clean, typed JavaScript interfaces.
4
+
5
+ This library focuses on **true native behavior**, not JavaScript re-implementations — starting with:
6
+
7
+ - **SelectionMenu** – native selection menus (Material on Android, system menus on iOS, web fallback)
8
+ - **DatePicker** – native date & time pickers with modal and inline presentations
9
+
10
+ The goal is to provide components that:
11
+
12
+ - Feel **100% native** on each platform
13
+ - Support modern platform design systems (Material 2 / Material 3 on Android, system pickers on iOS)
14
+ - Offer **headless** and **inline** modes for maximum layout control
15
+ - Integrate cleanly with **React Native Codegen / Fabric**
16
+ - Degrade gracefully on **Web**
17
+
18
+ ---
19
+
20
+ ## 🎥 Demos
21
+
22
+ ### SelectionMenu
23
+ Native Material / system selection menus with headless and inline modes.
24
+
25
+ 📹 **Demo video:**
26
+ 👉 *(add SelectionMenu demo link here)*
27
+
28
+ ---
29
+
30
+ ### DatePicker
31
+ Native date & time pickers using platform system UI.
32
+
33
+ 📹 **Demo video:**
34
+ 👉 *(add DatePicker demo link here)*
35
+
36
+ ---
37
+
38
+ ## 📦 Installation
39
+
40
+ ```sh
41
+ npm install react-native-platform-components
42
+ # or
43
+ yarn add react-native-platform-components
44
+ ```
45
+
46
+ ### iOS
47
+
48
+ ```sh
49
+ cd ios
50
+ pod install
51
+ ```
52
+
53
+ - Minimum iOS version: **iOS 13+**
54
+ - Uses `UIDatePicker` and system selection menus
55
+
56
+ ### Android
57
+
58
+ - Uses native Android Views
59
+ - Supports **Material 2** and **Material 3**
60
+ - No additional setup required beyond autolinking
61
+
62
+ ### Web
63
+
64
+ - **SelectionMenu** is supported with a web-appropriate fallback
65
+ - **DatePicker** currently targets native platforms only
66
+
67
+ ---
68
+
69
+ ## 🚀 Quick Start
70
+
71
+ ### SelectionMenu (Headless)
72
+
73
+ ```tsx
74
+ import { SelectionMenu } from 'react-native-platform-components';
75
+
76
+ const options = [
77
+ { label: 'Apple', data: 'apple' },
78
+ { label: 'Banana', data: 'banana' },
79
+ { label: 'Orange', data: 'orange' },
80
+ ];
81
+
82
+ export function Example() {
83
+ const [visible, setVisible] = React.useState(false);
84
+ const [value, setValue] = React.useState<string | null>(null);
85
+
86
+ return (
87
+ <>
88
+ <Button title="Open menu" onPress={() => setVisible(true)} />
89
+
90
+ <SelectionMenu
91
+ options={options}
92
+ selected={value}
93
+ visible={visible}
94
+ onSelect={(data) => {
95
+ setValue(data);
96
+ setVisible(false);
97
+ }}
98
+ onRequestClose={() => setVisible(false)}
99
+ />
100
+ </>
101
+ );
102
+ }
103
+ ```
104
+
105
+ ---
106
+
107
+ ### DatePicker (Modal)
108
+
109
+ ```tsx
110
+ import { DatePicker } from 'react-native-platform-components';
111
+
112
+ export function Example() {
113
+ const [date, setDate] = React.useState<Date | null>(null);
114
+ const [visible, setVisible] = React.useState(false);
115
+
116
+ return (
117
+ <>
118
+ <Button title="Pick date" onPress={() => setVisible(true)} />
119
+
120
+ <DatePicker
121
+ date={date}
122
+ visible={visible}
123
+ presentation="modal"
124
+ onConfirm={(d) => {
125
+ setDate(d);
126
+ setVisible(false);
127
+ }}
128
+ onClosed={() => setVisible(false)}
129
+ />
130
+ </>
131
+ );
132
+ }
133
+ ```
134
+
135
+ ---
136
+
137
+ ## 🧩 Components
138
+
139
+ ## SelectionMenu
140
+
141
+ Native selection menu with **inline** and **headless** modes.
142
+
143
+ ### Props
144
+
145
+ ```ts
146
+ type SelectionMenuProps = {
147
+ style?: StyleProp<ViewStyle>;
148
+
149
+ options: readonly {
150
+ label: string;
151
+ data: string;
152
+ }[];
153
+
154
+ selected: string | null;
155
+
156
+ disabled?: boolean;
157
+ placeholder?: string;
158
+
159
+ inlineMode?: boolean;
160
+ visible?: boolean;
161
+
162
+ presentation?: 'auto' | 'popover' | 'sheet';
163
+
164
+ onSelect?: (data: string, label: string, index: number) => void;
165
+ onRequestClose?: () => void;
166
+
167
+ ios?: {};
168
+
169
+ android?: {
170
+ material?: 'auto' | 'm2' | 'm3';
171
+ };
172
+ };
173
+ ```
174
+
175
+ ---
176
+
177
+ ## DatePicker
178
+
179
+ Native date & time picker using **platform system pickers**.
180
+
181
+ ### Props
182
+
183
+ ```ts
184
+ type DatePickerProps = {
185
+ style?: StyleProp<ViewStyle>;
186
+
187
+ date: Date | null;
188
+
189
+ minDate?: Date | null;
190
+ maxDate?: Date | null;
191
+
192
+ locale?: string;
193
+ timeZoneName?: string;
194
+
195
+ mode?: 'date' | 'time' | 'dateAndTime' | 'countDownTimer';
196
+ presentation?: 'modal' | 'inline';
197
+
198
+ visible?: boolean;
199
+
200
+ onConfirm?: (dateTime: Date) => void;
201
+ onClosed?: () => void;
202
+
203
+ ios?: {
204
+ preferredStyle?: 'automatic' | 'wheels' | 'inline' | 'compact';
205
+ countDownDurationSeconds?: number;
206
+ minuteInterval?: number;
207
+ roundsToMinuteInterval?: boolean;
208
+ };
209
+
210
+ android?: {
211
+ firstDayOfWeek?: number;
212
+ material?: 'auto' | 'm2' | 'm3';
213
+ dialogTitle?: string;
214
+ positiveButtonTitle?: string;
215
+ negativeButtonTitle?: string;
216
+ };
217
+ };
218
+ ```
219
+
220
+ ---
221
+
222
+ ## 🧠 Design Philosophy
223
+
224
+ - **Native first** — no JS re-implementation of pickers
225
+ - **Headless-friendly** — works with any custom UI
226
+ - **Codegen-safe** — string unions & sentinel values
227
+ - **Predictable behavior** — no surprise re-renders or layout hacks
228
+
229
+ ---
230
+
231
+ ## 📄 License
232
+
233
+ MIT
@@ -0,0 +1,78 @@
1
+ buildscript {
2
+ ext.getExtOrDefault = {name ->
3
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : project.properties['PlatformComponents_' + name]
4
+ }
5
+
6
+ repositories {
7
+ google()
8
+ mavenCentral()
9
+ }
10
+
11
+ dependencies {
12
+ classpath "com.android.tools.build:gradle:8.7.2"
13
+ // noinspection DifferentKotlinGradleVersion
14
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
15
+ }
16
+ }
17
+
18
+
19
+ apply plugin: "com.android.library"
20
+ apply plugin: "kotlin-android"
21
+
22
+ apply plugin: "com.facebook.react"
23
+
24
+ def getExtOrIntegerDefault(name) {
25
+ return rootProject.ext.has(name) ? rootProject.ext.get(name) : (project.properties["PlatformComponents_" + name]).toInteger()
26
+ }
27
+
28
+ android {
29
+ namespace "com.platformcomponents"
30
+
31
+ compileSdkVersion getExtOrIntegerDefault("compileSdkVersion")
32
+
33
+ defaultConfig {
34
+ minSdkVersion getExtOrIntegerDefault("minSdkVersion")
35
+ targetSdkVersion getExtOrIntegerDefault("targetSdkVersion")
36
+ }
37
+
38
+ buildFeatures {
39
+ buildConfig true
40
+ }
41
+
42
+ buildTypes {
43
+ release {
44
+ minifyEnabled false
45
+ }
46
+ }
47
+
48
+ lintOptions {
49
+ disable "GradleCompatible"
50
+ }
51
+
52
+ compileOptions {
53
+ sourceCompatibility JavaVersion.VERSION_1_8
54
+ targetCompatibility JavaVersion.VERSION_1_8
55
+ }
56
+
57
+ sourceSets {
58
+ main {
59
+ java.srcDirs += [
60
+ "generated/java",
61
+ "generated/jni"
62
+ ]
63
+ }
64
+ }
65
+ }
66
+
67
+ repositories {
68
+ mavenCentral()
69
+ google()
70
+ }
71
+
72
+ def kotlin_version = getExtOrDefault("kotlinVersion")
73
+
74
+ dependencies {
75
+ implementation "com.facebook.react:react-android"
76
+ implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
77
+ implementation "com.google.android.material:material:1.12.0"
78
+ }
@@ -0,0 +1,5 @@
1
+ PlatformComponents_kotlinVersion=2.0.21
2
+ PlatformComponents_minSdkVersion=24
3
+ PlatformComponents_targetSdkVersion=34
4
+ PlatformComponents_compileSdkVersion=35
5
+ PlatformComponents_ndkVersion=27.1.12297006
@@ -0,0 +1,2 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ </manifest>
@@ -0,0 +1,83 @@
1
+ package com.platformcomponents.datepicker
2
+
3
+ import com.google.android.material.datepicker.CalendarConstraints
4
+ import com.google.android.material.datepicker.DateValidatorPointBackward
5
+ import com.google.android.material.datepicker.DateValidatorPointForward
6
+ import java.util.TimeZone
7
+
8
+ object DateConstraints {
9
+ fun build(minMs: Double, maxMs: Double, firstDayOfWeek: Int?): CalendarConstraints? {
10
+ val hasMin = minMs >= 0
11
+ val hasMax = maxMs >= 0
12
+ if (!hasMin && !hasMax && firstDayOfWeek == null) return null
13
+
14
+ val builder = CalendarConstraints.Builder()
15
+
16
+ // First day of week: MaterialDatePicker uses java.util.Calendar constants. We map ISO 1..7.
17
+ firstDayOfWeek?.let {
18
+ val calDay = isoToCalendarDay(it)
19
+ if (calDay != null) builder.setFirstDayOfWeek(calDay)
20
+ }
21
+
22
+ val validators = ArrayList<CalendarConstraints.DateValidator>(2)
23
+ if (hasMin) validators.add(DateValidatorPointForward.from(minMs.toLong()))
24
+ if (hasMax) validators.add(DateValidatorPointBackward.before(maxMs.toLong()))
25
+
26
+ if (validators.isNotEmpty()) {
27
+ builder.setValidator(CompositeValidator(validators))
28
+ }
29
+
30
+ return builder.build()
31
+ }
32
+
33
+ private fun isoToCalendarDay(iso: Int): Int? {
34
+ // ISO: 1=Mon ... 7=Sun
35
+ return when (iso) {
36
+ 1 -> java.util.Calendar.MONDAY
37
+ 2 -> java.util.Calendar.TUESDAY
38
+ 3 -> java.util.Calendar.WEDNESDAY
39
+ 4 -> java.util.Calendar.THURSDAY
40
+ 5 -> java.util.Calendar.FRIDAY
41
+ 6 -> java.util.Calendar.SATURDAY
42
+ 7 -> java.util.Calendar.SUNDAY
43
+ else -> null
44
+ }
45
+ }
46
+
47
+ private class CompositeValidator(
48
+ private val validators: List<CalendarConstraints.DateValidator>
49
+ ) : CalendarConstraints.DateValidator {
50
+
51
+ override fun isValid(date: Long): Boolean {
52
+ for (v in validators) if (!v.isValid(date)) return false
53
+ return true
54
+ }
55
+
56
+ override fun describeContents(): Int = 0
57
+
58
+ override fun writeToParcel(dest: android.os.Parcel, flags: Int) {
59
+ dest.writeInt(validators.size)
60
+ validators.forEach { dest.writeParcelable(it, flags) }
61
+ }
62
+
63
+ companion object {
64
+ @JvmField
65
+ val CREATOR: android.os.Parcelable.Creator<CompositeValidator> =
66
+ object : android.os.Parcelable.Creator<CompositeValidator> {
67
+ override fun createFromParcel(source: android.os.Parcel): CompositeValidator {
68
+ val n = source.readInt()
69
+ val list = ArrayList<CalendarConstraints.DateValidator>(n)
70
+ repeat(n) {
71
+ val v = source.readParcelable<CalendarConstraints.DateValidator>(
72
+ CalendarConstraints.DateValidator::class.java.classLoader
73
+ )
74
+ if (v != null) list.add(v)
75
+ }
76
+ return CompositeValidator(list)
77
+ }
78
+
79
+ override fun newArray(size: Int): Array<CompositeValidator?> = arrayOfNulls(size)
80
+ }
81
+ }
82
+ }
83
+ }
@@ -0,0 +1,27 @@
1
+ package com.platformcomponents
2
+
3
+ import android.app.Activity
4
+ import android.content.Context
5
+ import android.content.ContextWrapper
6
+ import androidx.fragment.app.FragmentActivity
7
+ import com.facebook.react.uimanager.ThemedReactContext
8
+
9
+ public fun Context.findActivity(): Activity? {
10
+ var c: Context? = this
11
+ while (c is ContextWrapper) {
12
+ if (c is Activity) return c
13
+ c = c.baseContext
14
+ }
15
+ return null
16
+ }
17
+
18
+ public fun Context.findFragmentActivity(): FragmentActivity? {
19
+ // RN best-case
20
+ val trc = this as? ThemedReactContext
21
+ val a1 = trc?.currentActivity
22
+ if (a1 is FragmentActivity) return a1
23
+
24
+ // fallback unwrap
25
+ val a2 = this.findActivity()
26
+ return a2 as? FragmentActivity
27
+ }