bare-ui-kit 0.2.0 → 0.3.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/CMakeLists.txt +7 -1
- package/README.md +42 -1
- package/binding.m +558 -2
- package/index.d.ts +41 -0
- package/index.js +16 -0
- package/lib/activity-indicator-view.d.ts +29 -0
- package/lib/activity-indicator-view.h +181 -0
- package/lib/activity-indicator-view.js +56 -0
- package/lib/alert-action.d.ts +33 -0
- package/lib/alert-action.js +48 -0
- package/lib/alert-controller.d.ts +20 -0
- package/lib/alert-controller.h +199 -0
- package/lib/alert-controller.js +33 -0
- package/lib/attributed-string.d.ts +45 -0
- package/lib/attributed-string.h +176 -0
- package/lib/attributed-string.js +51 -0
- package/lib/attributes.js +34 -0
- package/lib/bezier-path.d.ts +26 -0
- package/lib/bezier-path.h +145 -0
- package/lib/bezier-path.js +51 -0
- package/lib/bridging.h +600 -2
- package/lib/color.d.ts +86 -0
- package/lib/color.h +286 -0
- package/lib/color.js +170 -0
- package/lib/events.js +35 -0
- package/lib/font-descriptor.d.ts +30 -0
- package/lib/font-descriptor.h +96 -0
- package/lib/font-descriptor.js +47 -0
- package/lib/font-metrics.d.ts +38 -0
- package/lib/font-metrics.h +109 -0
- package/lib/font-metrics.js +58 -0
- package/lib/font.d.ts +59 -0
- package/lib/font.h +424 -0
- package/lib/font.js +100 -0
- package/lib/handle.d.ts +5 -0
- package/lib/handle.js +6 -0
- package/lib/image-view.d.ts +15 -0
- package/lib/image-view.h +75 -0
- package/lib/image-view.js +27 -0
- package/lib/image.d.ts +37 -0
- package/lib/image.h +205 -0
- package/lib/image.js +60 -0
- package/lib/label.d.ts +51 -0
- package/lib/label.h +331 -0
- package/lib/label.js +94 -0
- package/lib/paragraph-style.d.ts +20 -0
- package/lib/paragraph-style.h +94 -0
- package/lib/paragraph-style.js +42 -0
- package/lib/pasteboard.d.ts +31 -0
- package/lib/pasteboard.h +123 -0
- package/lib/pasteboard.js +63 -0
- package/lib/retain.js +12 -0
- package/lib/runtime.m +92 -15
- package/lib/scene.d.ts +30 -0
- package/lib/scene.h +87 -0
- package/lib/scene.js +48 -0
- package/lib/scratch.js +4 -0
- package/lib/screen.d.ts +26 -0
- package/lib/screen.h +194 -0
- package/lib/screen.js +52 -0
- package/lib/scroll-view.d.ts +39 -0
- package/lib/scroll-view.h +246 -0
- package/lib/scroll-view.js +64 -0
- package/lib/switch.d.ts +22 -0
- package/lib/switch.h +166 -0
- package/lib/switch.js +42 -0
- package/lib/text-field.d.ts +103 -0
- package/lib/text-field.h +562 -0
- package/lib/text-field.js +183 -0
- package/lib/text-view.d.ts +59 -0
- package/lib/text-view.h +497 -0
- package/lib/text-view.js +138 -0
- package/lib/view-controller.d.ts +37 -0
- package/lib/view-controller.h +108 -20
- package/lib/view-controller.js +50 -5
- package/lib/view.d.ts +158 -0
- package/lib/view.h +1385 -20
- package/lib/view.js +276 -7
- package/lib/window.d.ts +44 -0
- package/lib/window.h +167 -27
- package/lib/window.js +62 -9
- package/lib/wrap.js +7 -0
- package/package.json +12 -3
- package/prebuilds/ios-arm64/bare +0 -0
- package/prebuilds/ios-arm64/bare-ui-kit.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ui-kit.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ui-kit.bare +0 -0
package/lib/pasteboard.h
ADDED
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
#import <assert.h>
|
|
2
|
+
#import <bare.h>
|
|
3
|
+
#import <js.h>
|
|
4
|
+
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
#import "bridging.h"
|
|
8
|
+
|
|
9
|
+
static js_value_t *
|
|
10
|
+
bare_ui_kit_pasteboard_general_pasteboard(js_env_t *env, js_callback_info_t *info) {
|
|
11
|
+
int err;
|
|
12
|
+
|
|
13
|
+
bare_ui_kit_state_t *state;
|
|
14
|
+
err = js_get_callback_info(env, info, NULL, NULL, NULL, (void **) &state);
|
|
15
|
+
assert(err == 0);
|
|
16
|
+
|
|
17
|
+
js_value_t *result;
|
|
18
|
+
|
|
19
|
+
@autoreleasepool {
|
|
20
|
+
result = bare_foundation_bridge(env, state->registry, [UIPasteboard generalPasteboard]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static js_value_t *
|
|
27
|
+
bare_ui_kit_pasteboard_string(js_env_t *env, js_callback_info_t *info) {
|
|
28
|
+
int err;
|
|
29
|
+
|
|
30
|
+
size_t argc = 2;
|
|
31
|
+
js_value_t *argv[2];
|
|
32
|
+
|
|
33
|
+
bare_ui_kit_state_t *state;
|
|
34
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
35
|
+
assert(err == 0);
|
|
36
|
+
|
|
37
|
+
assert(argc == 1 || argc == 2);
|
|
38
|
+
|
|
39
|
+
void *handle;
|
|
40
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
41
|
+
|
|
42
|
+
js_value_t *result = NULL;
|
|
43
|
+
|
|
44
|
+
@autoreleasepool {
|
|
45
|
+
UIPasteboard *pasteboard = (__bridge UIPasteboard *) handle;
|
|
46
|
+
|
|
47
|
+
if (argc == 1) {
|
|
48
|
+
result = bare_ui_kit__from_string(env, pasteboard.string);
|
|
49
|
+
} else {
|
|
50
|
+
pasteboard.string = bare_ui_kit__to_string(env, argv[1]);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
return result;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
#define V(name, property) \
|
|
58
|
+
static js_value_t * \
|
|
59
|
+
name(js_env_t *env, js_callback_info_t *info) { \
|
|
60
|
+
int err; \
|
|
61
|
+
\
|
|
62
|
+
size_t argc = 1; \
|
|
63
|
+
js_value_t *argv[1]; \
|
|
64
|
+
\
|
|
65
|
+
bare_ui_kit_state_t *state; \
|
|
66
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state); \
|
|
67
|
+
assert(err == 0); \
|
|
68
|
+
\
|
|
69
|
+
assert(argc == 1); \
|
|
70
|
+
\
|
|
71
|
+
void *handle; \
|
|
72
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL; \
|
|
73
|
+
\
|
|
74
|
+
js_value_t *result; \
|
|
75
|
+
\
|
|
76
|
+
@autoreleasepool { \
|
|
77
|
+
UIPasteboard *pasteboard = (__bridge UIPasteboard *) handle; \
|
|
78
|
+
\
|
|
79
|
+
err = js_get_boolean(env, pasteboard.property, &result); \
|
|
80
|
+
assert(err == 0); \
|
|
81
|
+
} \
|
|
82
|
+
\
|
|
83
|
+
return result; \
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
V(bare_ui_kit_pasteboard_has_strings, hasStrings)
|
|
87
|
+
V(bare_ui_kit_pasteboard_has_urls, hasURLs)
|
|
88
|
+
V(bare_ui_kit_pasteboard_has_images, hasImages)
|
|
89
|
+
V(bare_ui_kit_pasteboard_has_colors, hasColors)
|
|
90
|
+
#undef V
|
|
91
|
+
|
|
92
|
+
#define V(name, property) \
|
|
93
|
+
static js_value_t * \
|
|
94
|
+
name(js_env_t *env, js_callback_info_t *info) { \
|
|
95
|
+
int err; \
|
|
96
|
+
\
|
|
97
|
+
size_t argc = 1; \
|
|
98
|
+
js_value_t *argv[1]; \
|
|
99
|
+
\
|
|
100
|
+
bare_ui_kit_state_t *state; \
|
|
101
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state); \
|
|
102
|
+
assert(err == 0); \
|
|
103
|
+
\
|
|
104
|
+
assert(argc == 1); \
|
|
105
|
+
\
|
|
106
|
+
void *handle; \
|
|
107
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL; \
|
|
108
|
+
\
|
|
109
|
+
js_value_t *result; \
|
|
110
|
+
\
|
|
111
|
+
@autoreleasepool { \
|
|
112
|
+
UIPasteboard *pasteboard = (__bridge UIPasteboard *) handle; \
|
|
113
|
+
\
|
|
114
|
+
err = js_create_int64(env, pasteboard.property, &result); \
|
|
115
|
+
assert(err == 0); \
|
|
116
|
+
} \
|
|
117
|
+
\
|
|
118
|
+
return result; \
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
V(bare_ui_kit_pasteboard_number_of_items, numberOfItems)
|
|
122
|
+
V(bare_ui_kit_pasteboard_change_count, changeCount)
|
|
123
|
+
#undef V
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const registry = require('bare-foundation-registry')
|
|
3
|
+
const wrap = require('./wrap')
|
|
4
|
+
|
|
5
|
+
module.exports = exports = class UIKitPasteboard {
|
|
6
|
+
constructor(opts = {}) {
|
|
7
|
+
const { tag = null } = opts
|
|
8
|
+
|
|
9
|
+
this._tag = tag
|
|
10
|
+
|
|
11
|
+
this._token = binding.claim(this._tag, this)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
get [registry.tag]() {
|
|
15
|
+
return this._tag
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
get [registry.handle]() {
|
|
19
|
+
return binding.handle(this._tag)
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static get generalPasteboard() {
|
|
23
|
+
return wrap(UIKitPasteboard, binding.pasteboardGeneralPasteboard())
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
get string() {
|
|
27
|
+
return binding.pasteboardString(this._tag)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
set string(string) {
|
|
31
|
+
binding.pasteboardString(this._tag, string)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get hasStrings() {
|
|
35
|
+
return binding.pasteboardHasStrings(this._tag)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get hasURLs() {
|
|
39
|
+
return binding.pasteboardHasUrls(this._tag)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get hasImages() {
|
|
43
|
+
return binding.pasteboardHasImages(this._tag)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get hasColors() {
|
|
47
|
+
return binding.pasteboardHasColors(this._tag)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
get numberOfItems() {
|
|
51
|
+
return binding.pasteboardNumberOfItems(this._tag)
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
get changeCount() {
|
|
55
|
+
return binding.pasteboardChangeCount(this._tag)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
[Symbol.for('bare.inspect')]() {
|
|
59
|
+
return {
|
|
60
|
+
__proto__: { constructor: UIKitPasteboard }
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
package/lib/retain.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
const wrap = require('./wrap')
|
|
2
|
+
|
|
3
|
+
// Read the property every time, so the answer is right even when it was changed
|
|
4
|
+
// natively, and keep the result, because the reference from a native object to
|
|
5
|
+
// its wrapper is weak.
|
|
6
|
+
module.exports = exports = function retain(holder, key, Class, tag) {
|
|
7
|
+
const value = wrap(Class, tag)
|
|
8
|
+
|
|
9
|
+
holder[key] = value
|
|
10
|
+
|
|
11
|
+
return value
|
|
12
|
+
}
|
package/lib/runtime.m
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
#import <assert.h>
|
|
2
2
|
#import <bare.h>
|
|
3
|
+
#import <stdbool.h>
|
|
3
4
|
#import <js.h>
|
|
4
5
|
#import <path.h>
|
|
5
6
|
#import <rlimit.h>
|
|
@@ -20,6 +21,10 @@ static bare_t *bare;
|
|
|
20
21
|
|
|
21
22
|
static dispatch_source_t bare__poll;
|
|
22
23
|
static dispatch_source_t bare__timer;
|
|
24
|
+
static CFRunLoopObserverRef bare__observer;
|
|
25
|
+
|
|
26
|
+
static bool bare__exited;
|
|
27
|
+
static bool bare__running;
|
|
23
28
|
|
|
24
29
|
static void
|
|
25
30
|
bare__on_shutdown(uv_async_t *handle) {
|
|
@@ -59,9 +64,17 @@ static void
|
|
|
59
64
|
bare__run(void) {
|
|
60
65
|
int err;
|
|
61
66
|
|
|
67
|
+
if (bare__running) return;
|
|
68
|
+
|
|
69
|
+
bare__running = true;
|
|
70
|
+
|
|
62
71
|
err = bare_run(bare, UV_RUN_NOWAIT);
|
|
63
72
|
assert(err >= 0);
|
|
64
73
|
|
|
74
|
+
bare__running = false;
|
|
75
|
+
|
|
76
|
+
if (bare__exited) return;
|
|
77
|
+
|
|
65
78
|
int timeout = uv_backend_timeout(bare__loop);
|
|
66
79
|
|
|
67
80
|
if (timeout == 0) {
|
|
@@ -69,7 +82,12 @@ bare__run(void) {
|
|
|
69
82
|
bare__run();
|
|
70
83
|
});
|
|
71
84
|
} else if (timeout < 0) {
|
|
72
|
-
|
|
85
|
+
dispatch_source_set_timer(
|
|
86
|
+
bare__timer,
|
|
87
|
+
DISPATCH_TIME_FOREVER,
|
|
88
|
+
DISPATCH_TIME_FOREVER,
|
|
89
|
+
0
|
|
90
|
+
);
|
|
73
91
|
} else {
|
|
74
92
|
uint64_t nanoseconds = (uint64_t) timeout * NSEC_PER_MSEC;
|
|
75
93
|
|
|
@@ -125,6 +143,20 @@ bare__launch(void) {
|
|
|
125
143
|
dispatch_resume(bare__poll);
|
|
126
144
|
dispatch_resume(bare__timer);
|
|
127
145
|
|
|
146
|
+
bare__observer = CFRunLoopObserverCreateWithHandler(
|
|
147
|
+
NULL,
|
|
148
|
+
kCFRunLoopBeforeWaiting,
|
|
149
|
+
true,
|
|
150
|
+
0,
|
|
151
|
+
^(CFRunLoopObserverRef observer, CFRunLoopActivity activity) {
|
|
152
|
+
if (bare__exited) return;
|
|
153
|
+
|
|
154
|
+
bare__run();
|
|
155
|
+
}
|
|
156
|
+
);
|
|
157
|
+
|
|
158
|
+
CFRunLoopAddObserver(CFRunLoopGetMain(), bare__observer, kCFRunLoopCommonModes);
|
|
159
|
+
|
|
128
160
|
bare__run();
|
|
129
161
|
}
|
|
130
162
|
|
|
@@ -132,17 +164,23 @@ static void
|
|
|
132
164
|
bare__terminate(void) {
|
|
133
165
|
int err;
|
|
134
166
|
|
|
167
|
+
CFRunLoopRemoveObserver(CFRunLoopGetMain(), bare__observer, kCFRunLoopCommonModes);
|
|
168
|
+
|
|
169
|
+
CFRelease(bare__observer);
|
|
170
|
+
|
|
135
171
|
dispatch_source_cancel(bare__poll);
|
|
136
172
|
dispatch_source_cancel(bare__timer);
|
|
137
173
|
|
|
138
174
|
err = uv_async_send(&bare__shutdown);
|
|
139
175
|
assert(err == 0);
|
|
140
176
|
|
|
141
|
-
|
|
142
|
-
|
|
177
|
+
if (!bare__exited) {
|
|
178
|
+
err = bare_terminate(bare);
|
|
179
|
+
assert(err == 0);
|
|
143
180
|
|
|
144
|
-
|
|
145
|
-
|
|
181
|
+
err = bare_run(bare, UV_RUN_DEFAULT);
|
|
182
|
+
assert(err == 0);
|
|
183
|
+
}
|
|
146
184
|
|
|
147
185
|
int exit_code;
|
|
148
186
|
err = bare_teardown(bare, UV_RUN_DEFAULT, &exit_code);
|
|
@@ -159,6 +197,17 @@ bare__terminate(void) {
|
|
|
159
197
|
if (exit_code != 0) _exit(exit_code);
|
|
160
198
|
}
|
|
161
199
|
|
|
200
|
+
static void
|
|
201
|
+
bare__on_exit(bare_t *bare, void *data) {
|
|
202
|
+
bare__exited = true;
|
|
203
|
+
|
|
204
|
+
dispatch_async(dispatch_get_main_queue(), ^{
|
|
205
|
+
bare__terminate();
|
|
206
|
+
|
|
207
|
+
exit(0);
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
|
|
162
211
|
static void
|
|
163
212
|
bare__background(void) {
|
|
164
213
|
int err;
|
|
@@ -173,32 +222,57 @@ bare__foreground(void) {
|
|
|
173
222
|
assert(err == 0);
|
|
174
223
|
}
|
|
175
224
|
|
|
176
|
-
|
|
225
|
+
// From iOS 26 an app that does not adopt the scene lifecycle traps on launch,
|
|
226
|
+
// so the scene is the entry point. Its window only exists once it connects, so
|
|
227
|
+
// the bundle is loaded here.
|
|
228
|
+
@interface BareSceneDelegate : NSObject <UIWindowSceneDelegate>
|
|
177
229
|
|
|
178
230
|
@end
|
|
179
231
|
|
|
180
|
-
@implementation
|
|
232
|
+
@implementation BareSceneDelegate
|
|
181
233
|
|
|
182
|
-
- (
|
|
183
|
-
|
|
234
|
+
- (void)scene:(UIScene *)scene willConnectToSession:(UISceneSession *)session options:(UISceneConnectionOptions *)options {
|
|
235
|
+
static bool launched = false;
|
|
184
236
|
|
|
185
|
-
return
|
|
186
|
-
}
|
|
237
|
+
if (launched) return;
|
|
187
238
|
|
|
188
|
-
|
|
189
|
-
|
|
239
|
+
launched = true;
|
|
240
|
+
|
|
241
|
+
bare__launch();
|
|
190
242
|
}
|
|
191
243
|
|
|
192
|
-
- (void)
|
|
244
|
+
- (void)sceneDidEnterBackground:(UIScene *)scene {
|
|
193
245
|
bare__background();
|
|
194
246
|
}
|
|
195
247
|
|
|
196
|
-
- (void)
|
|
248
|
+
- (void)sceneWillEnterForeground:(UIScene *)scene {
|
|
197
249
|
bare__foreground();
|
|
198
250
|
}
|
|
199
251
|
|
|
200
252
|
@end
|
|
201
253
|
|
|
254
|
+
@interface BareApp : UIApplication <UIApplicationDelegate>
|
|
255
|
+
|
|
256
|
+
@end
|
|
257
|
+
|
|
258
|
+
@implementation BareApp
|
|
259
|
+
|
|
260
|
+
- (UISceneConfiguration *)application:(UIApplication *)application configurationForConnectingSceneSession:(UISceneSession *)session options:(UISceneConnectionOptions *)options {
|
|
261
|
+
UISceneConfiguration *configuration = [UISceneConfiguration
|
|
262
|
+
configurationWithName:@"Default"
|
|
263
|
+
sessionRole:session.role];
|
|
264
|
+
|
|
265
|
+
configuration.delegateClass = BareSceneDelegate.class;
|
|
266
|
+
|
|
267
|
+
return configuration;
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
- (void)applicationWillTerminate:(UIApplication *)application {
|
|
271
|
+
bare__terminate();
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
@end
|
|
275
|
+
|
|
202
276
|
int
|
|
203
277
|
main(int argc, char *argv[]) {
|
|
204
278
|
int err;
|
|
@@ -271,6 +345,9 @@ main(int argc, char *argv[]) {
|
|
|
271
345
|
err = bare_setup(bare__loop, bare__platform, NULL, argc, (const char **) argv, NULL, &bare);
|
|
272
346
|
assert(err == 0);
|
|
273
347
|
|
|
348
|
+
err = bare_on_exit(bare, bare__on_exit, NULL);
|
|
349
|
+
assert(err == 0);
|
|
350
|
+
|
|
274
351
|
@autoreleasepool {
|
|
275
352
|
return UIApplicationMain(argc, argv, @"BareApp", @"BareApp");
|
|
276
353
|
}
|
package/lib/scene.d.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
import UIKitScreen = require('./screen')
|
|
3
|
+
|
|
4
|
+
/** A scene the app shows its windows in, as a `UIWindowScene`. */
|
|
5
|
+
interface UIKitScene {
|
|
6
|
+
readonly screen: UIKitScreen | null
|
|
7
|
+
|
|
8
|
+
/** Whether the scene is in the foreground, as an `ACTIVATION_STATE` constant. */
|
|
9
|
+
readonly activationState: number
|
|
10
|
+
|
|
11
|
+
readonly [tag]: number
|
|
12
|
+
|
|
13
|
+
readonly [handle]: Handle
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare class UIKitScene {
|
|
17
|
+
protected constructor()
|
|
18
|
+
|
|
19
|
+
/** The scenes that are connected. Put a window in one to show it. */
|
|
20
|
+
static readonly connected: UIKitScene[]
|
|
21
|
+
|
|
22
|
+
static readonly ACTIVATION_STATE: {
|
|
23
|
+
readonly UNATTACHED: number
|
|
24
|
+
readonly FOREGROUND_ACTIVE: number
|
|
25
|
+
readonly FOREGROUND_INACTIVE: number
|
|
26
|
+
readonly BACKGROUND: number
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export = UIKitScene
|
package/lib/scene.h
ADDED
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
#import <assert.h>
|
|
2
|
+
#import <bare.h>
|
|
3
|
+
#import <js.h>
|
|
4
|
+
|
|
5
|
+
#import <UIKit/UIKit.h>
|
|
6
|
+
|
|
7
|
+
#import "bridging.h"
|
|
8
|
+
|
|
9
|
+
static js_value_t *
|
|
10
|
+
bare_ui_kit_scene_connected(js_env_t *env, js_callback_info_t *info) {
|
|
11
|
+
int err;
|
|
12
|
+
|
|
13
|
+
bare_ui_kit_state_t *state;
|
|
14
|
+
err = js_get_callback_info(env, info, NULL, NULL, NULL, (void **) &state);
|
|
15
|
+
assert(err == 0);
|
|
16
|
+
|
|
17
|
+
js_value_t *result;
|
|
18
|
+
|
|
19
|
+
@autoreleasepool {
|
|
20
|
+
NSMutableArray<UIWindowScene *> *scenes = [NSMutableArray array];
|
|
21
|
+
|
|
22
|
+
for (UIScene *scene in UIApplication.sharedApplication.connectedScenes) {
|
|
23
|
+
if ([scene isKindOfClass:UIWindowScene.class]) {
|
|
24
|
+
[scenes addObject:(UIWindowScene *) scene];
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
result = bare_ui_kit__from_objects(env, state, scenes);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return result;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
static js_value_t *
|
|
35
|
+
bare_ui_kit_scene_screen(js_env_t *env, js_callback_info_t *info) {
|
|
36
|
+
int err;
|
|
37
|
+
|
|
38
|
+
size_t argc = 1;
|
|
39
|
+
js_value_t *argv[1];
|
|
40
|
+
|
|
41
|
+
bare_ui_kit_state_t *state;
|
|
42
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
43
|
+
assert(err == 0);
|
|
44
|
+
|
|
45
|
+
assert(argc == 1);
|
|
46
|
+
|
|
47
|
+
void *handle;
|
|
48
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
49
|
+
|
|
50
|
+
js_value_t *result;
|
|
51
|
+
|
|
52
|
+
@autoreleasepool {
|
|
53
|
+
UIWindowScene *scene = (__bridge UIWindowScene *) handle;
|
|
54
|
+
|
|
55
|
+
result = bare_foundation_bridge(env, state->registry, scene.screen);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return result;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
static js_value_t *
|
|
62
|
+
bare_ui_kit_scene_activation_state(js_env_t *env, js_callback_info_t *info) {
|
|
63
|
+
int err;
|
|
64
|
+
|
|
65
|
+
size_t argc = 1;
|
|
66
|
+
js_value_t *argv[1];
|
|
67
|
+
|
|
68
|
+
bare_ui_kit_state_t *state;
|
|
69
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
70
|
+
assert(err == 0);
|
|
71
|
+
|
|
72
|
+
assert(argc == 1);
|
|
73
|
+
|
|
74
|
+
void *handle;
|
|
75
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
76
|
+
|
|
77
|
+
js_value_t *result;
|
|
78
|
+
|
|
79
|
+
@autoreleasepool {
|
|
80
|
+
UIScene *scene = (__bridge UIScene *) handle;
|
|
81
|
+
|
|
82
|
+
err = js_create_int32(env, (int32_t) scene.activationState, &result);
|
|
83
|
+
assert(err == 0);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return result;
|
|
87
|
+
}
|
package/lib/scene.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const registry = require('bare-foundation-registry')
|
|
3
|
+
const retain = require('./retain')
|
|
4
|
+
const wrap = require('./wrap')
|
|
5
|
+
const UIKitScreen = require('./screen')
|
|
6
|
+
|
|
7
|
+
module.exports = exports = class UIKitScene {
|
|
8
|
+
constructor(opts = {}) {
|
|
9
|
+
const { tag = null } = opts
|
|
10
|
+
|
|
11
|
+
this._tag = tag
|
|
12
|
+
|
|
13
|
+
this._token = binding.claim(this._tag, this)
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
get [registry.tag]() {
|
|
17
|
+
return this._tag
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
get [registry.handle]() {
|
|
21
|
+
return binding.handle(this._tag)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static get connected() {
|
|
25
|
+
return binding.sceneConnected().map((tag) => wrap(UIKitScene, tag))
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get screen() {
|
|
29
|
+
return retain(this, '_screen', UIKitScreen, binding.sceneScreen(this._tag))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
get activationState() {
|
|
33
|
+
return binding.sceneActivationState(this._tag)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
[Symbol.for('bare.inspect')]() {
|
|
37
|
+
return {
|
|
38
|
+
__proto__: { constructor: UIKitScene }
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.ACTIVATION_STATE = {
|
|
44
|
+
UNATTACHED: binding.SCENE_ACTIVATION_STATE_UNATTACHED,
|
|
45
|
+
FOREGROUND_ACTIVE: binding.SCENE_ACTIVATION_STATE_FOREGROUND_ACTIVE,
|
|
46
|
+
FOREGROUND_INACTIVE: binding.SCENE_ACTIVATION_STATE_FOREGROUND_INACTIVE,
|
|
47
|
+
BACKGROUND: binding.SCENE_ACTIVATION_STATE_BACKGROUND
|
|
48
|
+
}
|
package/lib/scratch.js
ADDED
package/lib/screen.d.ts
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
|
|
3
|
+
/** A screen, as a `UIScreen`. */
|
|
4
|
+
interface UIKitScreen {
|
|
5
|
+
/** The bounds in points. */
|
|
6
|
+
readonly bounds: { x: number; y: number; width: number; height: number }
|
|
7
|
+
|
|
8
|
+
/** The bounds in pixels. */
|
|
9
|
+
readonly nativeBounds: { x: number; y: number; width: number; height: number }
|
|
10
|
+
|
|
11
|
+
readonly scale: number
|
|
12
|
+
|
|
13
|
+
readonly nativeScale: number
|
|
14
|
+
|
|
15
|
+
readonly [tag]: number
|
|
16
|
+
|
|
17
|
+
readonly [handle]: Handle
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
declare class UIKitScreen {
|
|
21
|
+
protected constructor()
|
|
22
|
+
|
|
23
|
+
static readonly mainScreen: UIKitScreen
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export = UIKitScreen
|