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/screen.h
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
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_screen_main_screen(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, [UIScreen mainScreen]);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return result;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static js_value_t *
|
|
27
|
+
bare_ui_kit_screen_bounds_into(js_env_t *env, js_callback_info_t *info) {
|
|
28
|
+
int err;
|
|
29
|
+
|
|
30
|
+
size_t argc = 3;
|
|
31
|
+
js_value_t *argv[3];
|
|
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 == 3);
|
|
38
|
+
|
|
39
|
+
void *handle;
|
|
40
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
41
|
+
|
|
42
|
+
uint32_t offset;
|
|
43
|
+
if (!bare_ui_kit__read_uint32(env, argv[2], "offset", &offset)) return NULL;
|
|
44
|
+
|
|
45
|
+
double *out;
|
|
46
|
+
|
|
47
|
+
if (!bare_ui_kit__buffer(env, argv[1], offset, 4, &out)) {
|
|
48
|
+
err = js_throw_type_error(env, NULL, "Expected an array buffer with room for 4 doubles");
|
|
49
|
+
assert(err == 0);
|
|
50
|
+
|
|
51
|
+
return NULL;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
@autoreleasepool {
|
|
55
|
+
UIScreen *screen = (__bridge UIScreen *) handle;
|
|
56
|
+
|
|
57
|
+
CGRect value = screen.bounds;
|
|
58
|
+
|
|
59
|
+
out[0] = value.origin.x;
|
|
60
|
+
out[1] = value.origin.y;
|
|
61
|
+
out[2] = value.size.width;
|
|
62
|
+
out[3] = value.size.height;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return NULL;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
static void
|
|
69
|
+
bare_ui_kit_screen_bounds_into_typed(js_value_t *receiver, int32_t bare_tag, js_value_t *bare_buffer, uint32_t bare_offset, js_typed_callback_info_t *info) {
|
|
70
|
+
int err;
|
|
71
|
+
|
|
72
|
+
bare_ui_kit_state_t *state;
|
|
73
|
+
|
|
74
|
+
js_env_t *env;
|
|
75
|
+
err = js_get_typed_callback_info(info, &env, (void **) &state);
|
|
76
|
+
assert(err == 0);
|
|
77
|
+
|
|
78
|
+
id bare_object = bare_foundation_object(state->registry, bare_tag);
|
|
79
|
+
|
|
80
|
+
if (bare_object == nil) return;
|
|
81
|
+
|
|
82
|
+
double *out;
|
|
83
|
+
|
|
84
|
+
if (!bare_ui_kit__buffer(env, bare_buffer, bare_offset, 4, &out)) return;
|
|
85
|
+
|
|
86
|
+
@autoreleasepool {
|
|
87
|
+
UIScreen *screen = (UIScreen *) bare_object;
|
|
88
|
+
|
|
89
|
+
CGRect value = screen.bounds;
|
|
90
|
+
|
|
91
|
+
out[0] = value.origin.x;
|
|
92
|
+
out[1] = value.origin.y;
|
|
93
|
+
out[2] = value.size.width;
|
|
94
|
+
out[3] = value.size.height;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static js_value_t *
|
|
99
|
+
bare_ui_kit_screen_native_bounds_into(js_env_t *env, js_callback_info_t *info) {
|
|
100
|
+
int err;
|
|
101
|
+
|
|
102
|
+
size_t argc = 3;
|
|
103
|
+
js_value_t *argv[3];
|
|
104
|
+
|
|
105
|
+
bare_ui_kit_state_t *state;
|
|
106
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
107
|
+
assert(err == 0);
|
|
108
|
+
|
|
109
|
+
assert(argc == 3);
|
|
110
|
+
|
|
111
|
+
void *handle;
|
|
112
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
113
|
+
|
|
114
|
+
uint32_t offset;
|
|
115
|
+
if (!bare_ui_kit__read_uint32(env, argv[2], "offset", &offset)) return NULL;
|
|
116
|
+
|
|
117
|
+
double *out;
|
|
118
|
+
|
|
119
|
+
if (!bare_ui_kit__buffer(env, argv[1], offset, 4, &out)) {
|
|
120
|
+
err = js_throw_type_error(env, NULL, "Expected an array buffer with room for 4 doubles");
|
|
121
|
+
assert(err == 0);
|
|
122
|
+
|
|
123
|
+
return NULL;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
@autoreleasepool {
|
|
127
|
+
UIScreen *screen = (__bridge UIScreen *) handle;
|
|
128
|
+
|
|
129
|
+
CGRect value = screen.nativeBounds;
|
|
130
|
+
|
|
131
|
+
out[0] = value.origin.x;
|
|
132
|
+
out[1] = value.origin.y;
|
|
133
|
+
out[2] = value.size.width;
|
|
134
|
+
out[3] = value.size.height;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return NULL;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
static js_value_t *
|
|
141
|
+
bare_ui_kit_screen_scale(js_env_t *env, js_callback_info_t *info) {
|
|
142
|
+
int err;
|
|
143
|
+
|
|
144
|
+
size_t argc = 1;
|
|
145
|
+
js_value_t *argv[1];
|
|
146
|
+
|
|
147
|
+
bare_ui_kit_state_t *state;
|
|
148
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
149
|
+
assert(err == 0);
|
|
150
|
+
|
|
151
|
+
assert(argc == 1);
|
|
152
|
+
|
|
153
|
+
void *handle;
|
|
154
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
155
|
+
|
|
156
|
+
js_value_t *result;
|
|
157
|
+
|
|
158
|
+
@autoreleasepool {
|
|
159
|
+
UIScreen *screen = (__bridge UIScreen *) handle;
|
|
160
|
+
|
|
161
|
+
err = js_create_double(env, screen.scale, &result);
|
|
162
|
+
assert(err == 0);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return result;
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
static js_value_t *
|
|
169
|
+
bare_ui_kit_screen_native_scale(js_env_t *env, js_callback_info_t *info) {
|
|
170
|
+
int err;
|
|
171
|
+
|
|
172
|
+
size_t argc = 1;
|
|
173
|
+
js_value_t *argv[1];
|
|
174
|
+
|
|
175
|
+
bare_ui_kit_state_t *state;
|
|
176
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
177
|
+
assert(err == 0);
|
|
178
|
+
|
|
179
|
+
assert(argc == 1);
|
|
180
|
+
|
|
181
|
+
void *handle;
|
|
182
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
183
|
+
|
|
184
|
+
js_value_t *result;
|
|
185
|
+
|
|
186
|
+
@autoreleasepool {
|
|
187
|
+
UIScreen *screen = (__bridge UIScreen *) handle;
|
|
188
|
+
|
|
189
|
+
err = js_create_double(env, screen.nativeScale, &result);
|
|
190
|
+
assert(err == 0);
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
return result;
|
|
194
|
+
}
|
package/lib/screen.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const registry = require('bare-foundation-registry')
|
|
3
|
+
const scratch = require('./scratch')
|
|
4
|
+
const wrap = require('./wrap')
|
|
5
|
+
|
|
6
|
+
module.exports = exports = class UIKitScreen {
|
|
7
|
+
constructor(opts = {}) {
|
|
8
|
+
const { tag = null } = opts
|
|
9
|
+
|
|
10
|
+
this._tag = tag
|
|
11
|
+
|
|
12
|
+
this._token = binding.claim(this._tag, this)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
get [registry.tag]() {
|
|
16
|
+
return this._tag
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
get [registry.handle]() {
|
|
20
|
+
return binding.handle(this._tag)
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
static get mainScreen() {
|
|
24
|
+
return wrap(UIKitScreen, binding.screenMainScreen())
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
get bounds() {
|
|
28
|
+
binding.screenBoundsInto(this._tag, scratch.buffer, 0)
|
|
29
|
+
|
|
30
|
+
return { x: scratch[0], y: scratch[1], width: scratch[2], height: scratch[3] }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
get nativeBounds() {
|
|
34
|
+
binding.screenNativeBoundsInto(this._tag, scratch.buffer, 0)
|
|
35
|
+
|
|
36
|
+
return { x: scratch[0], y: scratch[1], width: scratch[2], height: scratch[3] }
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
get scale() {
|
|
40
|
+
return binding.screenScale(this._tag)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
get nativeScale() {
|
|
44
|
+
return binding.screenNativeScale(this._tag)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
[Symbol.for('bare.inspect')]() {
|
|
48
|
+
return {
|
|
49
|
+
__proto__: { constructor: UIKitScreen }
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import UIKitView = require('./view')
|
|
2
|
+
|
|
3
|
+
/** A view that scrolls its content, as a `UIScrollView`. It does not report touches. */
|
|
4
|
+
interface UIKitScrollView<
|
|
5
|
+
M extends Record<keyof M, unknown[]> = UIKitScrollView.Events
|
|
6
|
+
> extends UIKitView<M> {
|
|
7
|
+
/** The size of what there is to scroll. A scroll view does not work it out from its subviews. */
|
|
8
|
+
get contentSize(): { width: number; height: number }
|
|
9
|
+
set contentSize(size: { width?: number; height?: number })
|
|
10
|
+
|
|
11
|
+
/** How far the content is scrolled. */
|
|
12
|
+
get contentOffset(): { x: number; y: number }
|
|
13
|
+
set contentOffset(offset: { x?: number; y?: number })
|
|
14
|
+
|
|
15
|
+
/** How the safe area insets the content, as a `CONTENT_INSET_ADJUSTMENT_BEHAVIOR` constant. */
|
|
16
|
+
contentInsetAdjustmentBehavior: number
|
|
17
|
+
|
|
18
|
+
/** The insets actually applied, safe area included. */
|
|
19
|
+
readonly adjustedContentInset: UIKitView.Insets
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
declare class UIKitScrollView<M extends Record<keyof M, unknown[]> = UIKitScrollView.Events> {
|
|
23
|
+
constructor(frame?: Partial<UIKitView.Rect>)
|
|
24
|
+
|
|
25
|
+
static readonly CONTENT_INSET_ADJUSTMENT_BEHAVIOR: {
|
|
26
|
+
readonly AUTOMATIC: number
|
|
27
|
+
readonly SCROLLABLE_AXES: number
|
|
28
|
+
readonly NEVER: number
|
|
29
|
+
readonly ALWAYS: number
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
declare namespace UIKitScrollView {
|
|
34
|
+
export interface Events {
|
|
35
|
+
didScroll: [offset: { x: number; y: number }]
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export = UIKitScrollView
|
|
@@ -0,0 +1,246 @@
|
|
|
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
|
+
enum {
|
|
10
|
+
bare_ui_kit_scroll_view_event_did_scroll = 1 << 0,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
// A scroll view is its own delegate, like every other class here.
|
|
14
|
+
@interface BareScrollView : UIScrollView <UIScrollViewDelegate, BareEventTarget> {
|
|
15
|
+
@public
|
|
16
|
+
js_env_t *env;
|
|
17
|
+
js_ref_t *ctx;
|
|
18
|
+
|
|
19
|
+
int32_t mask;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
@end
|
|
23
|
+
|
|
24
|
+
@implementation BareScrollView
|
|
25
|
+
|
|
26
|
+
- (void)dealloc {
|
|
27
|
+
int err;
|
|
28
|
+
|
|
29
|
+
err = js_delete_reference(env, ctx);
|
|
30
|
+
assert(err == 0);
|
|
31
|
+
|
|
32
|
+
[super dealloc];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
- (int32_t)eventMask {
|
|
36
|
+
return mask;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
- (void)setEventMask:(int32_t)value {
|
|
40
|
+
mask = value;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
- (void)scrollViewDidScroll:(UIScrollView *)view {
|
|
44
|
+
if ((mask & bare_ui_kit_scroll_view_event_did_scroll) == 0) return;
|
|
45
|
+
|
|
46
|
+
CGPoint offset = view.contentOffset;
|
|
47
|
+
|
|
48
|
+
bare_ui_kit__emit_point(env, ctx, "_ondidscroll", offset.x, offset.y);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@end
|
|
52
|
+
|
|
53
|
+
static js_value_t *
|
|
54
|
+
bare_ui_kit_scroll_view_init(js_env_t *env, js_callback_info_t *info) {
|
|
55
|
+
int err;
|
|
56
|
+
|
|
57
|
+
size_t argc = 5;
|
|
58
|
+
js_value_t *argv[5];
|
|
59
|
+
|
|
60
|
+
bare_ui_kit_state_t *state;
|
|
61
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
62
|
+
assert(err == 0);
|
|
63
|
+
|
|
64
|
+
assert(argc == 5);
|
|
65
|
+
|
|
66
|
+
double x;
|
|
67
|
+
if (!bare_ui_kit__read_double(env, argv[0], "x", &x)) return NULL;
|
|
68
|
+
|
|
69
|
+
double y;
|
|
70
|
+
if (!bare_ui_kit__read_double(env, argv[1], "y", &y)) return NULL;
|
|
71
|
+
|
|
72
|
+
double width;
|
|
73
|
+
if (!bare_ui_kit__read_double(env, argv[2], "width", &width)) return NULL;
|
|
74
|
+
|
|
75
|
+
double height;
|
|
76
|
+
if (!bare_ui_kit__read_double(env, argv[3], "height", &height)) return NULL;
|
|
77
|
+
|
|
78
|
+
js_value_t *result;
|
|
79
|
+
|
|
80
|
+
@autoreleasepool {
|
|
81
|
+
BareScrollView *handle = [[[BareScrollView alloc]
|
|
82
|
+
initWithFrame:CGRectMake(x, y, width, height)] autorelease];
|
|
83
|
+
|
|
84
|
+
result = bare_foundation_bridge(env, state->registry, handle);
|
|
85
|
+
|
|
86
|
+
handle->env = env;
|
|
87
|
+
|
|
88
|
+
err = js_create_reference(env, argv[4], 0, &handle->ctx);
|
|
89
|
+
assert(err == 0);
|
|
90
|
+
|
|
91
|
+
handle.delegate = handle;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return result;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
static js_value_t *
|
|
98
|
+
bare_ui_kit_scroll_view_content_size(js_env_t *env, js_callback_info_t *info) {
|
|
99
|
+
int err;
|
|
100
|
+
|
|
101
|
+
size_t argc = 3;
|
|
102
|
+
js_value_t *argv[3];
|
|
103
|
+
|
|
104
|
+
bare_ui_kit_state_t *state;
|
|
105
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
106
|
+
assert(err == 0);
|
|
107
|
+
|
|
108
|
+
assert(argc == 1 || argc == 3);
|
|
109
|
+
|
|
110
|
+
void *handle;
|
|
111
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
112
|
+
|
|
113
|
+
js_value_t *result = NULL;
|
|
114
|
+
|
|
115
|
+
@autoreleasepool {
|
|
116
|
+
UIScrollView *view = (__bridge UIScrollView *) handle;
|
|
117
|
+
|
|
118
|
+
if (argc == 1) {
|
|
119
|
+
result = bare_ui_kit__from_size(env, view.contentSize);
|
|
120
|
+
} else {
|
|
121
|
+
double width;
|
|
122
|
+
if (!bare_ui_kit__read_double(env, argv[1], "width", &width)) return NULL;
|
|
123
|
+
|
|
124
|
+
double height;
|
|
125
|
+
if (!bare_ui_kit__read_double(env, argv[2], "height", &height)) return NULL;
|
|
126
|
+
|
|
127
|
+
view.contentSize = CGSizeMake(width, height);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
static js_value_t *
|
|
135
|
+
bare_ui_kit_scroll_view_content_inset_adjustment_behavior(js_env_t *env, js_callback_info_t *info) {
|
|
136
|
+
int err;
|
|
137
|
+
|
|
138
|
+
size_t argc = 2;
|
|
139
|
+
js_value_t *argv[2];
|
|
140
|
+
|
|
141
|
+
bare_ui_kit_state_t *state;
|
|
142
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
143
|
+
assert(err == 0);
|
|
144
|
+
|
|
145
|
+
assert(argc == 1 || argc == 2);
|
|
146
|
+
|
|
147
|
+
void *handle;
|
|
148
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
149
|
+
|
|
150
|
+
js_value_t *result = NULL;
|
|
151
|
+
|
|
152
|
+
@autoreleasepool {
|
|
153
|
+
UIScrollView *view = (__bridge UIScrollView *) handle;
|
|
154
|
+
|
|
155
|
+
if (argc == 1) {
|
|
156
|
+
err = js_create_int32(env, (int32_t) view.contentInsetAdjustmentBehavior, &result);
|
|
157
|
+
assert(err == 0);
|
|
158
|
+
} else {
|
|
159
|
+
double behavior;
|
|
160
|
+
if (!bare_ui_kit__read_double(env, argv[1], "behavior", &behavior)) return NULL;
|
|
161
|
+
|
|
162
|
+
view.contentInsetAdjustmentBehavior = (UIScrollViewContentInsetAdjustmentBehavior) behavior;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
return result;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
static js_value_t *
|
|
170
|
+
bare_ui_kit_scroll_view_adjusted_content_inset_into(js_env_t *env, js_callback_info_t *info) {
|
|
171
|
+
int err;
|
|
172
|
+
|
|
173
|
+
size_t argc = 3;
|
|
174
|
+
js_value_t *argv[3];
|
|
175
|
+
|
|
176
|
+
bare_ui_kit_state_t *state;
|
|
177
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
178
|
+
assert(err == 0);
|
|
179
|
+
|
|
180
|
+
assert(argc == 3);
|
|
181
|
+
|
|
182
|
+
void *handle;
|
|
183
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
184
|
+
|
|
185
|
+
uint32_t offset;
|
|
186
|
+
if (!bare_ui_kit__read_uint32(env, argv[2], "offset", &offset)) return NULL;
|
|
187
|
+
|
|
188
|
+
double *out;
|
|
189
|
+
|
|
190
|
+
if (!bare_ui_kit__buffer(env, argv[1], offset, 4, &out)) {
|
|
191
|
+
err = js_throw_type_error(env, NULL, "Expected an array buffer with room for 4 doubles");
|
|
192
|
+
assert(err == 0);
|
|
193
|
+
|
|
194
|
+
return NULL;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
@autoreleasepool {
|
|
198
|
+
UIScrollView *view = (__bridge UIScrollView *) handle;
|
|
199
|
+
|
|
200
|
+
UIEdgeInsets value = view.adjustedContentInset;
|
|
201
|
+
|
|
202
|
+
out[0] = value.top;
|
|
203
|
+
out[1] = value.left;
|
|
204
|
+
out[2] = value.bottom;
|
|
205
|
+
out[3] = value.right;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return NULL;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
static js_value_t *
|
|
212
|
+
bare_ui_kit_scroll_view_content_offset(js_env_t *env, js_callback_info_t *info) {
|
|
213
|
+
int err;
|
|
214
|
+
|
|
215
|
+
size_t argc = 3;
|
|
216
|
+
js_value_t *argv[3];
|
|
217
|
+
|
|
218
|
+
bare_ui_kit_state_t *state;
|
|
219
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
220
|
+
assert(err == 0);
|
|
221
|
+
|
|
222
|
+
assert(argc == 1 || argc == 3);
|
|
223
|
+
|
|
224
|
+
void *handle;
|
|
225
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
226
|
+
|
|
227
|
+
js_value_t *result = NULL;
|
|
228
|
+
|
|
229
|
+
@autoreleasepool {
|
|
230
|
+
UIScrollView *view = (__bridge UIScrollView *) handle;
|
|
231
|
+
|
|
232
|
+
if (argc == 1) {
|
|
233
|
+
result = bare_ui_kit__from_point(env, view.contentOffset);
|
|
234
|
+
} else {
|
|
235
|
+
double x;
|
|
236
|
+
if (!bare_ui_kit__read_double(env, argv[1], "x", &x)) return NULL;
|
|
237
|
+
|
|
238
|
+
double y;
|
|
239
|
+
if (!bare_ui_kit__read_double(env, argv[2], "y", &y)) return NULL;
|
|
240
|
+
|
|
241
|
+
view.contentOffset = CGPointMake(x, y);
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
return result;
|
|
246
|
+
}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const scratch = require('./scratch')
|
|
3
|
+
const UIKitView = require('./view')
|
|
4
|
+
|
|
5
|
+
module.exports = exports = class UIKitScrollView extends UIKitView {
|
|
6
|
+
// A scroll view does not report touches, so it has its own events instead of
|
|
7
|
+
// those of a view.
|
|
8
|
+
static _events = {
|
|
9
|
+
didScroll: binding.SCROLL_VIEW_EVENT_DID_SCROLL
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
_init(opts) {
|
|
13
|
+
const { x = 0, y = 0, width = 0, height = 0 } = opts
|
|
14
|
+
|
|
15
|
+
return binding.scrollViewInit(x, y, width, height, this)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
_ondidscroll(x, y) {
|
|
19
|
+
this.emit('didScroll', { x, y })
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
get contentSize() {
|
|
23
|
+
return binding.scrollViewContentSize(this._tag)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
set contentSize({ width = 0, height = 0 }) {
|
|
27
|
+
binding.scrollViewContentSize(this._tag, width, height)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
get contentOffset() {
|
|
31
|
+
return binding.scrollViewContentOffset(this._tag)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
set contentOffset({ x = 0, y = 0 }) {
|
|
35
|
+
binding.scrollViewContentOffset(this._tag, x, y)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
get contentInsetAdjustmentBehavior() {
|
|
39
|
+
return binding.scrollViewContentInsetAdjustmentBehavior(this._tag)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
set contentInsetAdjustmentBehavior(behavior) {
|
|
43
|
+
binding.scrollViewContentInsetAdjustmentBehavior(this._tag, behavior)
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
get adjustedContentInset() {
|
|
47
|
+
binding.scrollViewAdjustedContentInsetInto(this._tag, scratch.buffer, 0)
|
|
48
|
+
|
|
49
|
+
return { top: scratch[0], left: scratch[1], bottom: scratch[2], right: scratch[3] }
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
[Symbol.for('bare.inspect')]() {
|
|
53
|
+
return {
|
|
54
|
+
__proto__: { constructor: UIKitScrollView }
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
exports.CONTENT_INSET_ADJUSTMENT_BEHAVIOR = {
|
|
60
|
+
AUTOMATIC: binding.SCROLL_VIEW_CONTENT_INSET_ADJUSTMENT_BEHAVIOR_AUTOMATIC,
|
|
61
|
+
SCROLLABLE_AXES: binding.SCROLL_VIEW_CONTENT_INSET_ADJUSTMENT_BEHAVIOR_SCROLLABLE_AXES,
|
|
62
|
+
NEVER: binding.SCROLL_VIEW_CONTENT_INSET_ADJUSTMENT_BEHAVIOR_NEVER,
|
|
63
|
+
ALWAYS: binding.SCROLL_VIEW_CONTENT_INSET_ADJUSTMENT_BEHAVIOR_ALWAYS
|
|
64
|
+
}
|
package/lib/switch.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import UIKitView = require('./view')
|
|
2
|
+
|
|
3
|
+
/** An on and off switch, as a `UISwitch`. */
|
|
4
|
+
interface UIKitSwitch extends UIKitView<UIKitSwitch.Events> {
|
|
5
|
+
/** Whether the switch is on. Named so it does not hide the `on()` method of the emitter. */
|
|
6
|
+
isOn: boolean
|
|
7
|
+
|
|
8
|
+
enabled: boolean
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare class UIKitSwitch {
|
|
12
|
+
constructor(frame?: Partial<UIKitView.Rect>)
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare namespace UIKitSwitch {
|
|
16
|
+
export interface Events {
|
|
17
|
+
/** The user turned the switch on or off. Setting `isOn` does not emit this. */
|
|
18
|
+
valueChanged: []
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export = UIKitSwitch
|