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/switch.h
ADDED
|
@@ -0,0 +1,166 @@
|
|
|
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_switch_event_value_changed = 1 << 0,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
@interface BareSwitch : UISwitch <BareEventTarget> {
|
|
14
|
+
@public
|
|
15
|
+
js_env_t *env;
|
|
16
|
+
js_ref_t *ctx;
|
|
17
|
+
|
|
18
|
+
int32_t mask;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@end
|
|
22
|
+
|
|
23
|
+
@implementation BareSwitch
|
|
24
|
+
|
|
25
|
+
- (void)dealloc {
|
|
26
|
+
int err;
|
|
27
|
+
|
|
28
|
+
err = js_delete_reference(env, ctx);
|
|
29
|
+
assert(err == 0);
|
|
30
|
+
|
|
31
|
+
[super dealloc];
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
- (int32_t)eventMask {
|
|
35
|
+
return mask;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
- (void)setEventMask:(int32_t)value {
|
|
39
|
+
mask = value;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// A `UIControl` reports through a target and an action. It only does so when
|
|
43
|
+
// the user changes the value, never when the value is set.
|
|
44
|
+
- (void)bareValueChanged:(id)sender {
|
|
45
|
+
if ((mask & bare_ui_kit_switch_event_value_changed) == 0) return;
|
|
46
|
+
|
|
47
|
+
bare_ui_kit__emit(env, ctx, "_onvaluechanged");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@end
|
|
51
|
+
|
|
52
|
+
static js_value_t *
|
|
53
|
+
bare_ui_kit_switch_init(js_env_t *env, js_callback_info_t *info) {
|
|
54
|
+
int err;
|
|
55
|
+
|
|
56
|
+
size_t argc = 5;
|
|
57
|
+
js_value_t *argv[5];
|
|
58
|
+
|
|
59
|
+
bare_ui_kit_state_t *state;
|
|
60
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
61
|
+
assert(err == 0);
|
|
62
|
+
|
|
63
|
+
assert(argc == 5);
|
|
64
|
+
|
|
65
|
+
double x;
|
|
66
|
+
if (!bare_ui_kit__read_double(env, argv[0], "x", &x)) return NULL;
|
|
67
|
+
|
|
68
|
+
double y;
|
|
69
|
+
if (!bare_ui_kit__read_double(env, argv[1], "y", &y)) return NULL;
|
|
70
|
+
|
|
71
|
+
double width;
|
|
72
|
+
if (!bare_ui_kit__read_double(env, argv[2], "width", &width)) return NULL;
|
|
73
|
+
|
|
74
|
+
double height;
|
|
75
|
+
if (!bare_ui_kit__read_double(env, argv[3], "height", &height)) return NULL;
|
|
76
|
+
|
|
77
|
+
js_value_t *result;
|
|
78
|
+
|
|
79
|
+
@autoreleasepool {
|
|
80
|
+
BareSwitch *handle = [[[BareSwitch alloc]
|
|
81
|
+
initWithFrame:CGRectMake(x, y, width, height)] autorelease];
|
|
82
|
+
|
|
83
|
+
result = bare_foundation_bridge(env, state->registry, handle);
|
|
84
|
+
|
|
85
|
+
handle->env = env;
|
|
86
|
+
|
|
87
|
+
err = js_create_reference(env, argv[4], 0, &handle->ctx);
|
|
88
|
+
assert(err == 0);
|
|
89
|
+
|
|
90
|
+
[handle addTarget:handle
|
|
91
|
+
action:@selector(bareValueChanged:)
|
|
92
|
+
forControlEvents:UIControlEventValueChanged];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
static js_value_t *
|
|
99
|
+
bare_ui_kit_switch_on(js_env_t *env, js_callback_info_t *info) {
|
|
100
|
+
int err;
|
|
101
|
+
|
|
102
|
+
size_t argc = 2;
|
|
103
|
+
js_value_t *argv[2];
|
|
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 == 1 || argc == 2);
|
|
110
|
+
|
|
111
|
+
void *handle;
|
|
112
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
113
|
+
|
|
114
|
+
js_value_t *result = NULL;
|
|
115
|
+
|
|
116
|
+
@autoreleasepool {
|
|
117
|
+
UISwitch *control = (__bridge UISwitch *) handle;
|
|
118
|
+
|
|
119
|
+
if (argc == 1) {
|
|
120
|
+
err = js_get_boolean(env, control.on, &result);
|
|
121
|
+
assert(err == 0);
|
|
122
|
+
} else {
|
|
123
|
+
bool value;
|
|
124
|
+
if (!bare_ui_kit__read_bool(env, argv[1], "on", &value)) return NULL;
|
|
125
|
+
|
|
126
|
+
control.on = value;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
static js_value_t *
|
|
134
|
+
bare_ui_kit_switch_enabled(js_env_t *env, js_callback_info_t *info) {
|
|
135
|
+
int err;
|
|
136
|
+
|
|
137
|
+
size_t argc = 2;
|
|
138
|
+
js_value_t *argv[2];
|
|
139
|
+
|
|
140
|
+
bare_ui_kit_state_t *state;
|
|
141
|
+
err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
|
|
142
|
+
assert(err == 0);
|
|
143
|
+
|
|
144
|
+
assert(argc == 1 || argc == 2);
|
|
145
|
+
|
|
146
|
+
void *handle;
|
|
147
|
+
if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
|
|
148
|
+
|
|
149
|
+
js_value_t *result = NULL;
|
|
150
|
+
|
|
151
|
+
@autoreleasepool {
|
|
152
|
+
UISwitch *control = (__bridge UISwitch *) handle;
|
|
153
|
+
|
|
154
|
+
if (argc == 1) {
|
|
155
|
+
err = js_get_boolean(env, control.enabled, &result);
|
|
156
|
+
assert(err == 0);
|
|
157
|
+
} else {
|
|
158
|
+
bool value;
|
|
159
|
+
if (!bare_ui_kit__read_bool(env, argv[1], "enabled", &value)) return NULL;
|
|
160
|
+
|
|
161
|
+
control.enabled = value;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
return result;
|
|
166
|
+
}
|
package/lib/switch.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const UIKitControl = require('./view')
|
|
3
|
+
|
|
4
|
+
module.exports = exports = class UIKitSwitch extends UIKitControl {
|
|
5
|
+
_init(opts) {
|
|
6
|
+
const { x = 0, y = 0, width = 0, height = 0 } = opts
|
|
7
|
+
|
|
8
|
+
return binding.switchInit(x, y, width, height, this)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
// Named `isOn`, because a property called `on` would hide the `on()` method
|
|
12
|
+
// of the emitter.
|
|
13
|
+
get isOn() {
|
|
14
|
+
return binding.switchOn(this._tag)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
set isOn(value) {
|
|
18
|
+
binding.switchOn(this._tag, value)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
get enabled() {
|
|
22
|
+
return binding.switchEnabled(this._tag)
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
set enabled(enabled) {
|
|
26
|
+
binding.switchEnabled(this._tag, enabled)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[Symbol.for('bare.inspect')]() {
|
|
30
|
+
return {
|
|
31
|
+
__proto__: { constructor: UIKitSwitch }
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
_onvaluechanged() {
|
|
36
|
+
this.emit('valueChanged')
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports._events = {
|
|
41
|
+
valueChanged: binding.SWITCH_EVENT_VALUE_CHANGED
|
|
42
|
+
}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
|
|
2
|
+
import UIKitView = require('./view')
|
|
3
|
+
import UIKitColor = require('./color')
|
|
4
|
+
import UIKitFont = require('./font')
|
|
5
|
+
|
|
6
|
+
/** A single line of editable text, as a `UITextField`. */
|
|
7
|
+
interface UIKitTextField extends UIKitView<UIKitTextField.Events> {
|
|
8
|
+
text: string | null
|
|
9
|
+
|
|
10
|
+
/** Text shown while the field is empty. */
|
|
11
|
+
placeholder: string | null
|
|
12
|
+
|
|
13
|
+
get font(): UIKitFont | null
|
|
14
|
+
set font(font: Wrapper | null)
|
|
15
|
+
|
|
16
|
+
get textColor(): UIKitColor | null
|
|
17
|
+
set textColor(color: Wrapper | null)
|
|
18
|
+
|
|
19
|
+
/** A `UIKitLabel.TEXT_ALIGNMENT` constant. */
|
|
20
|
+
textAlignment: number
|
|
21
|
+
|
|
22
|
+
/** A `UIKitTextField.KEYBOARD_TYPE` constant. */
|
|
23
|
+
keyboardType: number
|
|
24
|
+
|
|
25
|
+
/** A `UIKitTextField.RETURN_KEY_TYPE` constant. */
|
|
26
|
+
returnKeyType: number
|
|
27
|
+
|
|
28
|
+
/** A `UIKitTextField.TEXT_AUTOCAPITALIZATION_TYPE` constant. */
|
|
29
|
+
autocapitalizationType: number
|
|
30
|
+
|
|
31
|
+
/** A `UIKitTextField.TEXT_AUTOCORRECTION_TYPE` constant. */
|
|
32
|
+
autocorrectionType: number
|
|
33
|
+
|
|
34
|
+
/** The selected range, as UTF-16 offsets. With nothing selected, `length` is 0. */
|
|
35
|
+
get selectedRange(): { location: number; length: number }
|
|
36
|
+
set selectedRange(range: { location?: number; length?: number })
|
|
37
|
+
|
|
38
|
+
/** Whether the text is hidden, as for a password. */
|
|
39
|
+
secureTextEntry: boolean
|
|
40
|
+
|
|
41
|
+
enabled: boolean
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
declare class UIKitTextField {
|
|
45
|
+
constructor(frame?: Partial<UIKitView.Rect>)
|
|
46
|
+
|
|
47
|
+
static readonly KEYBOARD_TYPE: {
|
|
48
|
+
readonly DEFAULT: number
|
|
49
|
+
readonly NUMBER_PAD: number
|
|
50
|
+
readonly DECIMAL_PAD: number
|
|
51
|
+
readonly NUMBERS_AND_PUNCTUATION: number
|
|
52
|
+
readonly EMAIL_ADDRESS: number
|
|
53
|
+
readonly PHONE_PAD: number
|
|
54
|
+
readonly URL: number
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
static readonly RETURN_KEY_TYPE: {
|
|
58
|
+
readonly DEFAULT: number
|
|
59
|
+
readonly DONE: number
|
|
60
|
+
readonly GO: number
|
|
61
|
+
readonly NEXT: number
|
|
62
|
+
readonly SEARCH: number
|
|
63
|
+
readonly SEND: number
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
static readonly TEXT_AUTOCAPITALIZATION_TYPE: {
|
|
67
|
+
readonly NONE: number
|
|
68
|
+
readonly WORDS: number
|
|
69
|
+
readonly SENTENCES: number
|
|
70
|
+
readonly ALL_CHARACTERS: number
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
static readonly TEXT_AUTOCORRECTION_TYPE: {
|
|
74
|
+
readonly DEFAULT: number
|
|
75
|
+
readonly NO: number
|
|
76
|
+
readonly YES: number
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
declare namespace UIKitTextField {
|
|
81
|
+
export interface Edit {
|
|
82
|
+
location: number
|
|
83
|
+
length: number
|
|
84
|
+
string: string
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export interface Events {
|
|
88
|
+
didBeginEditing: []
|
|
89
|
+
didEndEditing: []
|
|
90
|
+
|
|
91
|
+
/** The text changed. */
|
|
92
|
+
didChange: []
|
|
93
|
+
didChangeSelection: []
|
|
94
|
+
|
|
95
|
+
/** The `length` characters at `location` are about to be replaced by `string`. */
|
|
96
|
+
shouldChangeCharacters: [edit: Edit]
|
|
97
|
+
|
|
98
|
+
/** The user pressed the return key. */
|
|
99
|
+
shouldReturn: []
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
export = UIKitTextField
|