@octane-xplat/date-picker 0.18.0 → 0.20.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.
Files changed (35) hide show
  1. package/README.md +2 -139
  2. package/package.json +87 -81
  3. package/src/AppKitDatePicker.macos.css +1 -0
  4. package/src/AppKitDatePicker.macos.tsrx +43 -41
  5. package/src/AppKitDatePicker.tsrx +2 -0
  6. package/src/MaterialDatePicker.android.tsrx +51 -36
  7. package/src/MaterialDatePicker.tsrx +2 -0
  8. package/src/SwiftUIDatePicker.ios.tsrx +56 -37
  9. package/src/SwiftUIDatePicker.tsrx +2 -0
  10. package/src/android/index.ts +4 -4
  11. package/src/android/types.ts +151 -66
  12. package/src/date-picker-owner.macos.ts +264 -0
  13. package/src/ios/index.ts +3 -3
  14. package/src/ios/types.ts +29 -20
  15. package/src/macos/index.ts +3 -3
  16. package/src/macos/types.ts +27 -18
  17. package/src/style-merge.ts +59 -0
  18. package/types/generated/.tsrx-typegen-manifest.json +17 -0
  19. package/types/generated/AppKitDatePicker.macos.d.ts +10 -0
  20. package/types/generated/MaterialDatePicker.android.d.ts +15 -0
  21. package/types/generated/SwiftUIDatePicker.ios.d.ts +15 -0
  22. package/types/generated/android/index.d.ts +2 -0
  23. package/types/generated/android/types.d.ts +126 -0
  24. package/types/generated/date-picker-owner.macos.d.ts +29 -0
  25. package/types/generated/index.d.ts +1 -0
  26. package/types/generated/ios/index.d.ts +2 -0
  27. package/types/generated/ios/types.d.ts +33 -0
  28. package/types/generated/macos/index.d.ts +2 -0
  29. package/types/generated/macos/types.d.ts +31 -0
  30. package/types/generated/style-merge.d.ts +8 -0
  31. package/LICENSE +0 -21
  32. package/types/android/index.d.ts +0 -61
  33. package/types/index.d.ts +0 -1
  34. package/types/ios/index.d.ts +0 -21
  35. package/types/macos/index.d.ts +0 -20
package/README.md CHANGED
@@ -1,142 +1,5 @@
1
1
  # `@octane-xplat/date-picker`
2
2
 
3
- Platform-specific date and time pickers for Octane xplat apps: a SwiftUI
4
- `DatePicker` on iOS, Material 3 `DatePicker`/`TimePicker` built with Jetpack
5
- Compose on Android, and a real `NSDatePicker` on macOS. For portable form
6
- controls that work on every target, use `Calendar`, `DateInput`,
7
- `TimeInput`, `DateTimeInput`, and `DateRangeInput` from `@octane-xplat/ui`.
3
+ [Documentation](https://octane-xplat.goddardai.org/package-date-picker).
8
4
 
9
- ```tsx
10
- import { useState } from 'octane'
11
- import { DateInput } from '@octane-xplat/ui'
12
-
13
- export function DepartureDate() {
14
- const [date, setDate] = useState<string | null>('2026-10-02')
15
- return <DateInput value={date} onChange={setDate} label="Departure" />
16
- }
17
- ```
18
-
19
- There is no shared picker component. Install the package in the app that
20
- renders a control, then import `SwiftUIDatePicker` from
21
- `@octane-xplat/date-picker/ios`, `MaterialDatePicker` from
22
- `@octane-xplat/date-picker/android`, or `AppKitDatePicker` from
23
- `@octane-xplat/date-picker/macos` in the matching platform-suffixed file.
24
- These native entries have platform-specific contracts.
25
- The old `@octane-xplat/date-picker/web` `DateInput` subpath was removed because
26
- its browser-only string contract conflicted with the shared `DateInput` API.
27
-
28
- ```tsx
29
- /** @jsxImportSource @nativescript-community/octane */
30
- // SwiftUIDatePickerExample.ios.tsx
31
- import { SwiftUIDatePicker } from '@octane-xplat/date-picker/ios'
32
-
33
- export function Picker() {
34
- return (
35
- <SwiftUIDatePicker
36
- defaultSelection={new Date(2026, 9, 2)}
37
- displayedComponents={['date']}
38
- pickerStyle="graphical"
39
- onSelectionChange={console.log}
40
- />
41
- )
42
- }
43
- ```
44
-
45
- ```tsx
46
- /** @jsxImportSource @nativescript-community/octane */
47
- // MaterialDatePickerExample.android.tsx
48
- import { MaterialDatePicker } from '@octane-xplat/date-picker/android'
49
-
50
- const initialDate = new Date(2026, 9, 2)
51
- const bounds = { start: new Date(2026, 0, 1), end: new Date(2026, 11, 31) }
52
-
53
- export function Picker() {
54
- return (
55
- <MaterialDatePicker
56
- initialDate={initialDate}
57
- selectableDates={bounds}
58
- onDateSelected={console.log}
59
- />
60
- )
61
- }
62
- ```
63
-
64
- ```tsx
65
- // AppKitDatePickerExample.macos.tsx
66
- import { AppKitDatePicker } from '@octane-xplat/date-picker/macos'
67
-
68
- export function Picker() {
69
- return (
70
- <AppKitDatePicker
71
- components="date"
72
- pickerStyle="graphical"
73
- defaultSelection={new Date(2026, 9, 2)}
74
- onSelectionChange={console.log}
75
- />
76
- )
77
- }
78
- ```
79
-
80
- The platform APIs use their own selection vocabulary: the iOS entry takes a
81
- controlled `selection`/`defaultSelection` `Date` with `displayedComponents`
82
- and `pickerStyle`; the Android entry follows the uncontrolled
83
- `initialDate`/`onDateSelected` model of the Material 3 pickers with
84
- `selectableDates` range bounds; the macOS entry takes
85
- `components`/`pickerStyle` (`'graphical'` embeds the
86
- inline calendar) with a controlled `selection` `Date`.
87
-
88
- ```tsx
89
- // Departure.macos.tsx
90
- import { useState } from 'octane'
91
- import { AppKitDatePicker } from '@octane-xplat/date-picker/macos'
92
-
93
- export function Departure() {
94
- const [selection, setSelection] = useState(new Date(2026, 9, 2))
95
- return (
96
- <AppKitDatePicker
97
- components="date"
98
- pickerStyle="graphical"
99
- selection={selection}
100
- onSelectionChange={setSelection}
101
- />
102
- )
103
- }
104
- ```
105
-
106
- Android notes: give `MaterialDatePicker` a bounded height (the M3 calendar's
107
- lazy grid collapses under unbounded height), and keep `initialDate` and
108
- `selectableDates` identity-stable — the provider keys its state `remember`
109
- on them, so a per-render `new Date()` resets the selection.
110
- See the framework guide for details and maintained examples:
111
- [`docs/platform/date-picker.md`](../../docs/platform/date-picker.md).
112
-
113
- ```tsx
114
- /** @jsxImportSource @nativescript-community/octane */
115
- // Departure.android.tsx — reuse these objects while the picker is mounted.
116
- import { MaterialDatePicker } from '@octane-xplat/date-picker/android'
117
-
118
- const initialDate = new Date(2026, 9, 2)
119
- const selectableDates = { start: new Date(2026, 0, 1) }
120
- export function Departure() {
121
- return (
122
- <MaterialDatePicker
123
- className="departure-calendar"
124
- initialDate={initialDate}
125
- selectableDates={selectableDates}
126
- onDateSelected={console.log}
127
- />
128
- )
129
- }
130
- ```
131
-
132
- ```css
133
- /* App stylesheet: give the Android calendar room for its grid. */
134
- .departure-calendar {
135
- height: 480px;
136
- }
137
- ```
138
-
139
- The native implementations are adapted from `@expo/ui` (MIT,
140
- `packages/expo-ui` sdk-57): `ios/DatePickerView.swift` and
141
- `android/.../ui/DatePickerView.kt`. Attribution headers sit on the ported
142
- files.
5
+ [API reference](https://octane-xplat.goddardai.org/api-date-picker).
package/package.json CHANGED
@@ -1,82 +1,88 @@
1
1
  {
2
- "name": "@octane-xplat/date-picker",
3
- "version": "0.18.0",
4
- "description": "Platform-specific date and time selection controls for Octane xplat",
5
- "repository": {
6
- "type": "git",
7
- "url": "https://github.com/octane-xplat/octane-xplat",
8
- "directory": "packages/date-picker"
9
- },
10
- "files": [
11
- "types",
12
- "src",
13
- "platforms",
14
- "!src/**/*.test.*",
15
- "!src/**/*.spec.*"
16
- ],
17
- "type": "module",
18
- "exports": {
19
- ".": {
20
- "types": "./types/index.d.ts",
21
- "web": "./src/index.ts",
22
- "native": "./src/index.ts",
23
- "default": "./src/index.ts"
24
- },
25
- "./ios": {
26
- "types": "./types/ios/index.d.ts",
27
- "native": "./src/ios/index.ts"
28
- },
29
- "./android": {
30
- "types": "./types/android/index.d.ts",
31
- "native": "./src/android/index.ts"
32
- },
33
- "./macos": {
34
- "types": "./types/macos/index.d.ts",
35
- "macos": "./src/macos/index.ts"
36
- }
37
- },
38
- "publishConfig": {
39
- "access": "public"
40
- },
41
- "dependencies": {
42
- "@nativescript/jetpack-compose": "1.0.0-beta.0",
43
- "@nativescript/swift-ui": "4.0.2"
44
- },
45
- "devDependencies": {
46
- "@nativescript-community/octane": "0.2.5",
47
- "@nativescript/core": "9.1.3",
48
- "@octane-xplat/macos-renderer": "0.18.0",
49
- "@octanejs/vite-plugin": "0.1.61",
50
- "octane": "0.14.0",
51
- "tsrx-typegen": "0.4.0",
52
- "typescript": "5.9.3",
53
- "vite": "8.3.0"
54
- },
55
- "peerDependencies": {
56
- "@nativescript-community/octane": ">=0.2.1 <1",
57
- "@nativescript/core": ">=9.1.0 <10",
58
- "octane": ">=0.1.51 <1"
59
- },
60
- "peerDependenciesMeta": {
61
- "@nativescript-community/octane": {
62
- "optional": true
63
- },
64
- "@nativescript/core": {
65
- "optional": true
66
- },
67
- "octane": {
68
- "optional": true
69
- }
70
- },
71
- "nativescript": {
72
- "platforms": {
73
- "android": "9.1.0",
74
- "ios": "9.1.0"
75
- }
76
- },
77
- "scripts": {
78
- "test:packed": "node tests/packed-consumer.mjs",
79
- "pack:check": "tsrx-typegen --pack-check",
80
- "typegen": "tsc -p tsconfig.types.json"
81
- }
82
- }
2
+ "name": "@octane-xplat/date-picker",
3
+ "version": "0.20.0",
4
+ "description": "Platform-specific date and time selection controls for Octane xplat",
5
+ "repository": {
6
+ "type": "git",
7
+ "url": "https://github.com/octane-xplat/octane-xplat",
8
+ "directory": "packages/date-picker"
9
+ },
10
+ "files": [
11
+ "types/generated",
12
+ "src",
13
+ "platforms",
14
+ "!src/**/*.test.*",
15
+ "!src/**/*.spec.*"
16
+ ],
17
+ "type": "module",
18
+ "exports": {
19
+ ".": {
20
+ "types": "./types/generated/index.d.ts",
21
+ "web": "./src/index.ts",
22
+ "native": "./src/index.ts",
23
+ "default": "./src/index.ts"
24
+ },
25
+ "./ios": {
26
+ "types": "./types/generated/ios/index.d.ts",
27
+ "native": "./src/ios/index.ts"
28
+ },
29
+ "./android": {
30
+ "types": "./types/generated/android/index.d.ts",
31
+ "native": "./src/android/index.ts"
32
+ },
33
+ "./macos": {
34
+ "types": "./types/generated/macos/index.d.ts",
35
+ "macos": "./src/macos/index.ts"
36
+ }
37
+ },
38
+ "publishConfig": {
39
+ "access": "public"
40
+ },
41
+ "scripts": {
42
+ "prepack": "bun run typegen && tsrx-typegen --pack-check",
43
+ "test": "node --test tests/date-picker-owner.macos.test.mjs",
44
+ "test:packed": "node tests/packed-consumer.mjs",
45
+ "pack:check": "tsrx-typegen --pack-check",
46
+ "typegen": "tsrx-typegen --target date-picker",
47
+ "typecheck": "tsc --runExternalCode --noEmit -p tsconfig.types.json"
48
+ },
49
+ "dependencies": {
50
+ "@nativescript/jetpack-compose": "1.0.0-beta.0",
51
+ "@nativescript/swift-ui": "4.0.2",
52
+ "@octane-xplat/jsx": "0.20.0"
53
+ },
54
+ "devDependencies": {
55
+ "@nativescript-community/octane": "0.2.5",
56
+ "@nativescript/core": "9.1.3",
57
+ "@octane-xplat/macos-appkit": "0.20.0",
58
+ "@octanejs/vite-plugin": "0.5.0",
59
+ "octane": "0.16.3",
60
+ "tsrx-typegen": "0.6.1",
61
+ "typescript": "7.1.0-beta",
62
+ "vite": "8.3.6",
63
+ "@tsrx/content-mapper": "0.1.2"
64
+ },
65
+ "peerDependencies": {
66
+ "@nativescript-community/octane": ">=0.2.1 <1",
67
+ "@nativescript/core": ">=9.1.0 <10",
68
+ "octane": ">=0.1.51 <1"
69
+ },
70
+ "peerDependenciesMeta": {
71
+ "@nativescript-community/octane": {
72
+ "optional": true
73
+ },
74
+ "@nativescript/core": {
75
+ "optional": true
76
+ },
77
+ "octane": {
78
+ "optional": true
79
+ }
80
+ },
81
+ "nativescript": {
82
+ "platforms": {
83
+ "android": "9.1.0",
84
+ "ios": "9.1.0"
85
+ }
86
+ },
87
+ "types": "./types/generated/index.d.ts"
88
+ }
@@ -0,0 +1 @@
1
+ .xplat-appkit-date-picker { display: flex; min-width: 240; }
@@ -1,6 +1,10 @@
1
- /** @jsxImportSource @octane-xplat/macos-renderer */
2
- import { useEffect, useRef } from 'octane'
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
+ import './AppKitDatePicker.macos.css'
3
+ import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'octane'
3
4
  import type { AppKitDatePickerProps } from './macos/types'
5
+ import { createDatePickerOwner } from './date-picker-owner.macos'
6
+ import { mergeStyle } from './style-merge'
7
+ import type { DatePickerAttach } from './date-picker-owner.macos'
4
8
 
5
9
  const host = (): any => (globalThis as any).__xplatAppKit ?? {}
6
10
 
@@ -10,48 +14,46 @@ const host = (): any => (globalThis as any).__xplatAppKit ?? {}
10
14
  * clock-and-calendar field; 'dateAndTime' shows both element groups.
11
15
  * The host element carries an explicit size — the picker is pinned to
12
16
  * its edges. */
13
- export function AppKitDatePicker(props: AppKitDatePickerProps) @{
14
- const anchor = useRef<any>(null)
15
- const handle = useRef<any>(null)
17
+ export function AppKitDatePicker(props: AppKitDatePickerProps): unknown @{
18
+ const live = useRef(props)
16
19
 
17
- const options = () => ({
18
- mode: props.components,
19
- style: props.pickerStyle,
20
- selectionMillis: props.selection?.getTime?.(),
21
- minimumMillis: props.minimumDate?.getTime?.(),
22
- maximumMillis: props.maximumDate?.getTime?.(),
23
- enabled: !props.disabled,
24
- })
20
+ live.current = props
25
21
 
26
- useEffect(() => {
27
- const view = anchor.current
28
- const attach = host().attachDatePicker
29
- if (!view || typeof attach !== 'function') return
30
- // defaultSelection seeds the initial date; after that the user's
31
- // pick owns the value — only the controlled `selection` is pushed.
32
- handle.current = attach(
33
- view,
34
- { ...options(), selectionMillis: (props.selection ?? props.defaultSelection)?.getTime?.() },
35
- (millis: number) => {
36
- props.onSelectionChange?.(new Date(millis))
37
- },
38
- )
22
+ const [, rerender] = useState(0)
23
+ const owner = useMemo(
24
+ () =>
25
+ createDatePickerOwner({
26
+ props: () => live.current,
27
+ attach: () =>
28
+ typeof host().attachDatePicker === 'function'
29
+ ? (host().attachDatePicker as DatePickerAttach)
30
+ : undefined,
31
+ status: () => rerender((n) => n + 1),
32
+ }),
33
+ [],
34
+ )
39
35
 
40
- return () => {
41
- handle.current?.detach()
42
- handle.current = null
43
- }
44
- }, [props.components, props.pickerStyle])
36
+ useLayoutEffect(() => owner.update(), null)
37
+ useEffect(() => () => owner.dispose(), [])
45
38
 
46
- // Push controlled selection/range updates into the mounted picker; the
47
- // bridge update is echo-suppressed by comparing against dateValue.
48
- useEffect(() => {
49
- handle.current?.update(options())
50
- })
39
+ const graphical =
40
+ props.components === 'time' ||
41
+ ((props.components ?? 'date') === 'date' && props.pickerStyle === 'graphical')
51
42
 
52
- <masonview ref={(v: any) => { anchor.current = v }} id={props.id} className={props.className} style={{display: "flex", ...({
53
- minWidth: 240,
54
- minHeight: props.pickerStyle === 'graphical' ? 300 : 26,
55
- ...props.style,
56
- })}}/>;
43
+ <masonview
44
+ ref={owner.bind}
45
+ id={props.id}
46
+ className={['xplat-appkit-date-picker', props.className]}
47
+ style={mergeStyle({ minHeight: graphical ? 300 : 26 }, props.style)}
48
+ >
49
+ @if (owner.getStatus() === 'invalid') {
50
+ <label text="Choose a valid date and date range." accessibilityLiveRegion="polite" />
51
+ }
52
+ @if (owner.getStatus() === 'unavailable') {
53
+ <label
54
+ text="Date selection is unavailable in this app."
55
+ accessibilityLiveRegion="polite"
56
+ />
57
+ }
58
+ </masonview>
57
59
  }
@@ -0,0 +1,2 @@
1
+ // Type contract only. The target build must select a platform implementation.
2
+ export declare const AppKitDatePicker: typeof import('./AppKitDatePicker.macos.tsrx').AppKitDatePicker
@@ -1,49 +1,64 @@
1
- /** @jsxImportSource @nativescript-community/octane */
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { registerElement } from '@nativescript-community/octane'
3
- import type { Attributes } from '@nativescript-community/octane/intrinsics'
4
- import { ComposeDataDriver, JetpackCompose, registerJetpackCompose } from '@nativescript/jetpack-compose'
3
+ import type { Attributes } from '@octane-xplat/jsx/intrinsics'
4
+ import {
5
+ ComposeDataDriver,
6
+ JetpackCompose,
7
+ registerJetpackCompose,
8
+ } from '@nativescript/jetpack-compose'
9
+
5
10
  import type { MaterialDatePickerProps } from './android/types'
6
11
 
7
12
  declare const com: any
8
13
 
9
- declare module '@nativescript-community/octane/intrinsics' {
10
- interface NativeScriptElements {
11
- xplatandroiddatepicker: Attributes<typeof JetpackCompose>
12
- }
14
+ declare module '@octane-xplat/jsx/intrinsics' {
15
+ interface NativeElements<TElement> {
16
+ xplatandroiddatepicker: Attributes<
17
+ TElement,
18
+ {
19
+ composeId?: string
20
+ data?: Record<string, unknown>
21
+ onComposeEvent?: (event: { data?: unknown }) => void
22
+ }
23
+ >
24
+ }
13
25
  }
14
26
 
15
27
  registerElement('xplatandroiddatepicker', JetpackCompose)
16
- registerJetpackCompose('xplat-material-datepicker', (owner: any) =>
17
- new ComposeDataDriver(new com.octanexplat.datepicker.XplatDatePickerProvider(), owner),
28
+ registerJetpackCompose(
29
+ 'xplat-material-datepicker',
30
+ (owner: any) =>
31
+ new ComposeDataDriver(new com.octanexplat.datepicker.XplatDatePickerProvider(), owner),
18
32
  )
19
33
 
20
34
  /** Renders a Material 3 DatePicker/TimePicker through the NativeScript Jetpack Compose bridge. */
21
- export function MaterialDatePicker(props: MaterialDatePickerProps) @{
22
- const data = {
23
- initialDate: props.initialDate?.getTime() ?? null,
24
- variant: props.variant ?? 'picker',
25
- displayedComponents: props.displayedComponents ?? 'date',
26
- // The bridge's dataSerialize throws on booleans; send numbers.
27
- showVariantToggle: (props.showVariantToggle ?? true) ? 1 : 0,
28
- is24Hour: (props.is24Hour ?? true) ? 1 : 0,
29
- color: props.color,
30
- elementColors: props.elementColors,
31
- selectableDates: {
32
- start: props.selectableDates?.start?.getTime() ?? null,
33
- end: props.selectableDates?.end?.getTime() ?? null,
34
- },
35
- }
35
+ export function MaterialDatePicker(props: MaterialDatePickerProps): unknown @{
36
+ const data = {
37
+ initialDate: props.initialDate?.getTime() ?? null,
38
+ variant: props.variant ?? 'picker',
39
+ displayedComponents: props.displayedComponents ?? 'date',
40
+ // The bridge's dataSerialize throws on booleans; send numbers.
41
+ showVariantToggle: (props.showVariantToggle ?? true) ? 1 : 0,
42
+ is24Hour: (props.is24Hour ?? true) ? 1 : 0,
43
+ color: props.color,
44
+ elementColors: props.elementColors,
45
+ selectableDates: {
46
+ start: props.selectableDates?.start?.getTime() ?? null,
47
+ end: props.selectableDates?.end?.getTime() ?? null,
48
+ },
49
+ }
50
+
51
+ <xplatandroiddatepicker
52
+ id={props.id}
53
+ className={props.className}
54
+ style={props.style}
55
+ accessibilityLabel={props.accessibilityLabel}
56
+ composeId="xplat-material-datepicker"
57
+ data={data}
58
+ onComposeEvent={(event: any) => {
59
+ const millis = event.data?.date
36
60
 
37
- <xplatandroiddatepicker
38
- id={props.id}
39
- className={props.className}
40
- style={props.style}
41
- accessibilityLabel={props.accessibilityLabel}
42
- composeId="xplat-material-datepicker"
43
- data={data}
44
- onComposeEvent={(event: any) => {
45
- const millis = event.data?.date
46
- props.onDateSelected?.(typeof millis === 'number' ? new Date(millis) : null)
47
- }}
48
- />;
61
+ props.onDateSelected?.(typeof millis === 'number' ? new Date(millis) : null)
62
+ }}
63
+ />
49
64
  }
@@ -0,0 +1,2 @@
1
+ // Type contract only. The target build must select a platform implementation.
2
+ export declare const MaterialDatePicker: typeof import('./MaterialDatePicker.android.tsrx').MaterialDatePicker
@@ -1,51 +1,70 @@
1
- /** @jsxImportSource @nativescript-community/octane */
1
+ /** @jsxImportSource @octane-xplat/jsx */
2
2
  import { registerElement } from '@nativescript-community/octane'
3
- import type { Attributes } from '@nativescript-community/octane/intrinsics'
3
+ import type { Attributes } from '@octane-xplat/jsx/intrinsics'
4
4
  import { SwiftUI, UIDataDriver, registerSwiftUI } from '@nativescript/swift-ui'
5
5
  import { useState } from 'octane'
6
6
  import type { SwiftUIDatePickerProps } from './ios/types'
7
7
 
8
8
  declare const XplatDatePickerProvider: any
9
9
 
10
- declare module '@nativescript-community/octane/intrinsics' {
11
- interface NativeScriptElements {
12
- xplatiosdatepicker: Attributes<typeof SwiftUI>
13
- }
10
+ declare module '@octane-xplat/jsx/intrinsics' {
11
+ interface NativeElements<TElement> {
12
+ xplatiosdatepicker: Attributes<
13
+ TElement,
14
+ {
15
+ swiftId?: string
16
+ data?: Record<string, unknown>
17
+ onSwiftUIEvent?: (event: { data?: unknown }) => void
18
+ }
19
+ >
20
+ }
14
21
  }
15
22
 
16
23
  registerElement('xplatiosdatepicker', SwiftUI)
17
- registerSwiftUI('xplat-swiftui-datepicker', (owner: any) =>
18
- new UIDataDriver(new XplatDatePickerProvider(), owner),
24
+ registerSwiftUI(
25
+ 'xplat-swiftui-datepicker',
26
+ (owner: any) => new UIDataDriver(new XplatDatePickerProvider(), owner),
19
27
  )
20
28
 
21
29
  /** Renders a SwiftUI DatePicker through NativeScript's SwiftUI bridge. */
22
- export function SwiftUIDatePicker(props: SwiftUIDatePickerProps) @{
23
- const controlled = props.selection !== undefined
24
- const [internalSelection, setInternalSelection] = useState<Date | undefined>(props.defaultSelection)
25
- const selection = controlled ? props.selection! : internalSelection
26
-
27
- <xplatiosdatepicker
28
- id={props.id}
29
- className={props.className}
30
- style={props.style}
31
- swiftId="xplat-swiftui-datepicker"
32
- data={{
33
- title: props.title,
34
- selection: selection?.getTime(),
35
- range: {
36
- start: props.minimumDate?.getTime(),
37
- end: props.maximumDate?.getTime(),
38
- },
39
- displayedComponents: props.displayedComponents ?? ['date'],
40
- pickerStyle: props.pickerStyle ?? 'automatic',
41
- disabled: props.disabled ?? false,
42
- }}
43
- onSwiftUIEvent={(event: any) => {
44
- const millis = event.data?.date
45
- if (typeof millis !== 'number') return
46
- const next = new Date(millis)
47
- if (!controlled) setInternalSelection(next)
48
- props.onSelectionChange?.(next)
49
- }}
50
- />;
30
+ export function SwiftUIDatePicker(props: SwiftUIDatePickerProps): unknown @{
31
+ const controlled = props.selection !== undefined
32
+ const [internalSelection, setInternalSelection] = useState<Date | undefined>(
33
+ props.defaultSelection,
34
+ )
35
+
36
+ const selection = controlled ? props.selection! : internalSelection
37
+
38
+ <xplatiosdatepicker
39
+ id={props.id}
40
+ className={props.className}
41
+ style={props.style}
42
+ swiftId="xplat-swiftui-datepicker"
43
+ data={{
44
+ title: props.title,
45
+ selection: selection?.getTime(),
46
+ range: {
47
+ start: props.minimumDate?.getTime(),
48
+ end: props.maximumDate?.getTime(),
49
+ },
50
+ displayedComponents: props.displayedComponents ?? ['date'],
51
+ pickerStyle: props.pickerStyle ?? 'automatic',
52
+ disabled: props.disabled ?? false,
53
+ }}
54
+ onSwiftUIEvent={(event: any) => {
55
+ const millis = event.data?.date
56
+
57
+ if (typeof millis !== 'number') {
58
+ return
59
+ }
60
+
61
+ const next = new Date(millis)
62
+
63
+ if (!controlled) {
64
+ setInternalSelection(next)
65
+ }
66
+
67
+ props.onSelectionChange?.(next)
68
+ }}
69
+ />
51
70
  }
@@ -0,0 +1,2 @@
1
+ // Type contract only. The target build must select a platform implementation.
2
+ export declare const SwiftUIDatePicker: typeof import('./SwiftUIDatePicker.ios.tsrx').SwiftUIDatePicker
@@ -1,7 +1,7 @@
1
1
  export { MaterialDatePicker } from '../MaterialDatePicker.android.tsrx'
2
2
  export type {
3
- MaterialDatePickerComponents,
4
- MaterialDatePickerElementColors,
5
- MaterialDatePickerProps,
6
- MaterialDatePickerVariant,
3
+ MaterialDatePickerComponents,
4
+ MaterialDatePickerElementColors,
5
+ MaterialDatePickerProps,
6
+ MaterialDatePickerVariant,
7
7
  } from './types'