@octane-xplat/camera 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.
- package/README.md +2 -132
- package/package.json +108 -103
- package/platforms/android/java/com/octanexplat/camera/CameraPreviewView.java +24 -0
- package/platforms/android/java/com/octanexplat/camera/CameraSessionBridge.java +153 -21
- package/platforms/ios/src/XplatSwitchingMovieWriter.swift +557 -0
- package/src/CameraView.android.tsrx +194 -118
- package/src/CameraView.ios.tsrx +129 -76
- package/src/CameraView.macos.tsrx +108 -70
- package/src/CameraView.tsrx +2 -0
- package/src/CameraView.web.tsrx +160 -125
- package/src/CameraView.windows.tsrx +141 -92
- package/src/camera-host.macos.ts +1059 -0
- package/src/camera-permission.mobile.ts +85 -81
- package/src/camera-permission.windows.ts +56 -53
- package/src/camera-session.ios.ts +89 -61
- package/src/camera-session.macos.ts +51 -49
- package/src/camera-session.windows.ts +113 -105
- package/src/host-movie.web.ts +266 -222
- package/src/index.ts +28 -26
- package/src/index.web.ts +27 -25
- package/src/layout-child.ts +88 -79
- package/src/layout-child.web.ts +57 -51
- package/src/layout-child.windows.ts +82 -71
- package/src/movie-metadata.web.ts +87 -74
- package/src/movie-storage.web.ts +142 -135
- package/src/movie-writer.ios.ts +170 -0
- package/src/photo-lifecycle.macos.ts +60 -0
- package/src/photo-sheet.macos.ts +505 -0
- package/src/preview-display.ios.ts +69 -0
- package/src/preview-pinch.ts +41 -0
- package/src/preview-tap.ts +22 -21
- package/src/props.ts +118 -68
- package/src/recording-haptics.ios.ts +39 -0
- package/src/recording-source.web.ts +159 -0
- package/src/session-backend.android.ts +552 -410
- package/src/session-backend.ios.ts +1500 -1148
- package/src/session-backend.linux.ts +886 -860
- package/src/session-backend.macos.ts +697 -679
- package/src/session-backend.ts +51 -49
- package/src/session-backend.web.ts +1181 -867
- package/src/session-backend.windows.ts +1556 -1467
- package/src/session-core.ts +925 -711
- package/src/session.ts +12 -12
- package/src/style-merge.ts +43 -43
- package/src/synthetic-session.ts +392 -333
- package/src/types.ts +384 -239
- package/types/generated/.tsrx-typegen-manifest.json +18 -0
- package/types/generated/CameraView.d.ts +2 -0
- package/types/generated/CameraView.web.d.ts +4 -0
- package/types/generated/camera-host.macos.d.ts +33 -0
- package/types/generated/index.d.ts +34 -0
- package/types/generated/layout-child.web.d.ts +7 -0
- package/types/generated/photo-lifecycle.macos.d.ts +12 -0
- package/types/generated/photo-sheet.macos.d.ts +36 -0
- package/types/generated/props.d.ts +111 -0
- package/types/generated/session-backend.d.ts +6 -0
- package/types/{session-core.d.ts → generated/session-core.d.ts} +30 -1
- package/types/generated/session.d.ts +16 -0
- package/types/{synthetic-session.d.ts → generated/synthetic-session.d.ts} +15 -1
- package/types/{types.d.ts → generated/types.d.ts} +145 -2
- package/LICENSE +0 -21
- package/platforms/macos/src/CameraOwnership.swift +0 -22
- package/platforms/macos/src/PhotoCaptureLifecycle.swift +0 -34
- package/platforms/macos/src/XplatCameraHost.swift +0 -639
- package/platforms/macos/src/XplatPhotoCaptureSheet.swift +0 -192
- package/types/index.d.ts +0 -48
- package/types/props.d.ts +0 -61
|
@@ -1,26 +1,33 @@
|
|
|
1
|
-
/** @jsxImportSource @
|
|
1
|
+
/** @jsxImportSource @octane-xplat/jsx */
|
|
2
2
|
import { useImperativeHandle, useCallback, useEffect, useRef } from 'octane'
|
|
3
3
|
import { View } from '@nativescript/core'
|
|
4
4
|
import { registerElement } from '@nativescript-community/octane'
|
|
5
|
-
import type { Attributes } from '@
|
|
5
|
+
import type { Attributes } from '@octane-xplat/jsx/intrinsics'
|
|
6
6
|
import type { CameraViewProps } from './props'
|
|
7
7
|
import { attachSessionPreview } from './session'
|
|
8
8
|
import { cameraHardwarePresent, ensureCameraPermission } from './camera-permission.windows'
|
|
9
9
|
import { startCameraPreview } from './camera-session.windows'
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
applyEscapeProps,
|
|
12
|
+
layoutChildProps,
|
|
13
|
+
nativeAccessibilityRole,
|
|
14
|
+
nativeAccessibilityState,
|
|
15
|
+
} from './layout-child.windows'
|
|
16
|
+
|
|
11
17
|
import { observePreviewTap } from './preview-tap'
|
|
12
18
|
|
|
13
19
|
class CameraPreview extends View {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
20
|
+
createNativeView() {
|
|
21
|
+
const { Microsoft } = globalThis as any
|
|
22
|
+
|
|
23
|
+
return new Microsoft.UI.Xaml.Controls.CaptureElement()
|
|
24
|
+
}
|
|
18
25
|
}
|
|
19
26
|
|
|
20
|
-
declare module '@
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
27
|
+
declare module '@octane-xplat/jsx/intrinsics' {
|
|
28
|
+
interface NativeElements<TElement> {
|
|
29
|
+
camerapreview: Attributes<TElement, {}>
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
|
|
26
33
|
registerElement('camerapreview', CameraPreview)
|
|
@@ -28,85 +35,127 @@ registerElement('camerapreview', CameraPreview)
|
|
|
28
35
|
/** Live Windows preview backed by WinUI `CaptureElement` + `MediaCapture`.
|
|
29
36
|
* With `session`, the preview attaches to the session-owned capture so
|
|
30
37
|
* movie recording shares it; without one the view owns its capture. */
|
|
31
|
-
export function CameraView(props: CameraViewProps) @{
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
38
|
+
export function CameraView(props: CameraViewProps): unknown @{
|
|
39
|
+
const host = useRef<any>(null)
|
|
40
|
+
const active = props.active !== false
|
|
41
|
+
const facing = props.facing ?? 'back'
|
|
42
|
+
|
|
43
|
+
useImperativeHandle(props.ref, () => ({ native: host.current?.nativeViewProtected }), [])
|
|
44
|
+
|
|
45
|
+
const bindHost = useCallback((view: any) => {
|
|
46
|
+
host.current = view
|
|
47
|
+
}, [])
|
|
48
|
+
|
|
49
|
+
useEffect(() => {
|
|
50
|
+
const view = host.current
|
|
51
|
+
|
|
52
|
+
if (!view || !active) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
let disposed = false
|
|
57
|
+
let stopPreview: (() => Promise<void>) | undefined
|
|
58
|
+
const fail = (message: string) => props.onError?.({ message })
|
|
59
|
+
|
|
60
|
+
if (props.session) {
|
|
61
|
+
if (props.facing !== undefined) {
|
|
62
|
+
fail('camera session conflicts with facing')
|
|
63
|
+
return
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
try {
|
|
67
|
+
const detach = attachSessionPreview(props.session, view, {
|
|
68
|
+
onReady: () => {
|
|
69
|
+
if (!disposed) {
|
|
70
|
+
props.onReady?.()
|
|
71
|
+
}
|
|
72
|
+
},
|
|
73
|
+
onDisplayReady: () => {
|
|
74
|
+
if (!disposed) {
|
|
75
|
+
props.onDisplayReady?.()
|
|
76
|
+
}
|
|
77
|
+
},
|
|
78
|
+
onError: (issue) => {
|
|
79
|
+
if (!disposed) {
|
|
80
|
+
fail(issue.message)
|
|
81
|
+
}
|
|
82
|
+
},
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
return () => {
|
|
86
|
+
disposed = true
|
|
87
|
+
detach()
|
|
88
|
+
}
|
|
89
|
+
} catch (error: any) {
|
|
90
|
+
fail(error?.message ?? 'camera session error')
|
|
91
|
+
return
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (!cameraHardwarePresent()) {
|
|
96
|
+
fail('camera unsupported')
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
ensureCameraPermission().then(async (granted) => {
|
|
101
|
+
if (disposed) {
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (!granted) {
|
|
106
|
+
fail('camera permission denied')
|
|
107
|
+
return
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
try {
|
|
111
|
+
stopPreview = await startCameraPreview(view, facing, () => {
|
|
112
|
+
if (!disposed) {
|
|
113
|
+
props.onReady?.()
|
|
114
|
+
}
|
|
115
|
+
})
|
|
116
|
+
} catch (error: any) {
|
|
117
|
+
if (!disposed) {
|
|
118
|
+
fail(error?.message ?? 'camera error')
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
return () => {
|
|
124
|
+
disposed = true
|
|
125
|
+
void stopPreview?.()
|
|
126
|
+
}
|
|
127
|
+
}, [active, facing, props.session])
|
|
128
|
+
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
const view = host.current
|
|
131
|
+
|
|
132
|
+
if (!view) {
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
applyEscapeProps(view.nativeViewProtected, props)
|
|
137
|
+
}, [props.ref, props.windows])
|
|
138
|
+
|
|
139
|
+
useEffect(() => observePreviewTap(host.current, props.onTap), [props.onTap])
|
|
140
|
+
|
|
141
|
+
<masonview
|
|
142
|
+
id={props.id}
|
|
143
|
+
className={['vx-layers', 'vx-cameraview', props.className]}
|
|
144
|
+
{...layoutChildProps(props, {
|
|
145
|
+
display: 'grid',
|
|
146
|
+
gridTemplateRows: '1fr',
|
|
147
|
+
gridTemplateColumns: '1fr',
|
|
148
|
+
backgroundColor: '#000',
|
|
149
|
+
...props.style,
|
|
150
|
+
})}
|
|
151
|
+
accessible={props.accessible}
|
|
152
|
+
accessibilityLabel={props.accessibilityLabel}
|
|
153
|
+
accessibilityRole={nativeAccessibilityRole(props.accessibilityRole) as any}
|
|
154
|
+
accessibilityHint={props.accessibilityHint}
|
|
155
|
+
accessibilityValue={props.accessibilityValue}
|
|
156
|
+
accessibilityState={nativeAccessibilityState(props.accessibilityState) as any}
|
|
157
|
+
accessibilityLiveRegion={props.accessibilityLiveRegion as any}
|
|
158
|
+
>
|
|
159
|
+
<camerapreview ref={bindHost} style={{ gridRow: '1', gridColumn: '1' }} />
|
|
160
|
+
</masonview>
|
|
112
161
|
}
|