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.
Files changed (89) hide show
  1. package/CMakeLists.txt +7 -1
  2. package/README.md +42 -1
  3. package/binding.m +558 -2
  4. package/index.d.ts +41 -0
  5. package/index.js +16 -0
  6. package/lib/activity-indicator-view.d.ts +29 -0
  7. package/lib/activity-indicator-view.h +181 -0
  8. package/lib/activity-indicator-view.js +56 -0
  9. package/lib/alert-action.d.ts +33 -0
  10. package/lib/alert-action.js +48 -0
  11. package/lib/alert-controller.d.ts +20 -0
  12. package/lib/alert-controller.h +199 -0
  13. package/lib/alert-controller.js +33 -0
  14. package/lib/attributed-string.d.ts +45 -0
  15. package/lib/attributed-string.h +176 -0
  16. package/lib/attributed-string.js +51 -0
  17. package/lib/attributes.js +34 -0
  18. package/lib/bezier-path.d.ts +26 -0
  19. package/lib/bezier-path.h +145 -0
  20. package/lib/bezier-path.js +51 -0
  21. package/lib/bridging.h +600 -2
  22. package/lib/color.d.ts +86 -0
  23. package/lib/color.h +286 -0
  24. package/lib/color.js +170 -0
  25. package/lib/events.js +35 -0
  26. package/lib/font-descriptor.d.ts +30 -0
  27. package/lib/font-descriptor.h +96 -0
  28. package/lib/font-descriptor.js +47 -0
  29. package/lib/font-metrics.d.ts +38 -0
  30. package/lib/font-metrics.h +109 -0
  31. package/lib/font-metrics.js +58 -0
  32. package/lib/font.d.ts +59 -0
  33. package/lib/font.h +424 -0
  34. package/lib/font.js +100 -0
  35. package/lib/handle.d.ts +5 -0
  36. package/lib/handle.js +6 -0
  37. package/lib/image-view.d.ts +15 -0
  38. package/lib/image-view.h +75 -0
  39. package/lib/image-view.js +27 -0
  40. package/lib/image.d.ts +37 -0
  41. package/lib/image.h +205 -0
  42. package/lib/image.js +60 -0
  43. package/lib/label.d.ts +51 -0
  44. package/lib/label.h +331 -0
  45. package/lib/label.js +94 -0
  46. package/lib/paragraph-style.d.ts +20 -0
  47. package/lib/paragraph-style.h +94 -0
  48. package/lib/paragraph-style.js +42 -0
  49. package/lib/pasteboard.d.ts +31 -0
  50. package/lib/pasteboard.h +123 -0
  51. package/lib/pasteboard.js +63 -0
  52. package/lib/retain.js +12 -0
  53. package/lib/runtime.m +92 -15
  54. package/lib/scene.d.ts +30 -0
  55. package/lib/scene.h +87 -0
  56. package/lib/scene.js +48 -0
  57. package/lib/scratch.js +4 -0
  58. package/lib/screen.d.ts +26 -0
  59. package/lib/screen.h +194 -0
  60. package/lib/screen.js +52 -0
  61. package/lib/scroll-view.d.ts +39 -0
  62. package/lib/scroll-view.h +246 -0
  63. package/lib/scroll-view.js +64 -0
  64. package/lib/switch.d.ts +22 -0
  65. package/lib/switch.h +166 -0
  66. package/lib/switch.js +42 -0
  67. package/lib/text-field.d.ts +103 -0
  68. package/lib/text-field.h +562 -0
  69. package/lib/text-field.js +183 -0
  70. package/lib/text-view.d.ts +59 -0
  71. package/lib/text-view.h +497 -0
  72. package/lib/text-view.js +138 -0
  73. package/lib/view-controller.d.ts +37 -0
  74. package/lib/view-controller.h +108 -20
  75. package/lib/view-controller.js +50 -5
  76. package/lib/view.d.ts +158 -0
  77. package/lib/view.h +1385 -20
  78. package/lib/view.js +276 -7
  79. package/lib/window.d.ts +44 -0
  80. package/lib/window.h +167 -27
  81. package/lib/window.js +62 -9
  82. package/lib/wrap.js +7 -0
  83. package/package.json +12 -3
  84. package/prebuilds/ios-arm64/bare +0 -0
  85. package/prebuilds/ios-arm64/bare-ui-kit.bare +0 -0
  86. package/prebuilds/ios-arm64-simulator/bare +0 -0
  87. package/prebuilds/ios-arm64-simulator/bare-ui-kit.bare +0 -0
  88. package/prebuilds/ios-x64-simulator/bare +0 -0
  89. package/prebuilds/ios-x64-simulator/bare-ui-kit.bare +0 -0
package/index.d.ts ADDED
@@ -0,0 +1,41 @@
1
+ import ActivityIndicatorView = require('./lib/activity-indicator-view')
2
+ import AttributedString = require('./lib/attributed-string')
3
+ import BezierPath = require('./lib/bezier-path')
4
+ import Color = require('./lib/color')
5
+ import Font = require('./lib/font')
6
+ import FontDescriptor = require('./lib/font-descriptor')
7
+ import Image = require('./lib/image')
8
+ import ImageView = require('./lib/image-view')
9
+ import Label = require('./lib/label')
10
+ import ParagraphStyle = require('./lib/paragraph-style')
11
+ import Scene = require('./lib/scene')
12
+ import Screen = require('./lib/screen')
13
+ import ScrollView = require('./lib/scroll-view')
14
+ import Switch = require('./lib/switch')
15
+ import TextField = require('./lib/text-field')
16
+ import TextView = require('./lib/text-view')
17
+ import View = require('./lib/view')
18
+ import ViewController = require('./lib/view-controller')
19
+ import Window = require('./lib/window')
20
+
21
+ export {
22
+ ActivityIndicatorView,
23
+ AttributedString,
24
+ BezierPath,
25
+ Color,
26
+ Font,
27
+ FontDescriptor,
28
+ Image,
29
+ ImageView,
30
+ Label,
31
+ ParagraphStyle,
32
+ Scene,
33
+ Screen,
34
+ ScrollView,
35
+ Switch,
36
+ TextField,
37
+ TextView,
38
+ View,
39
+ ViewController,
40
+ Window
41
+ }
package/index.js CHANGED
@@ -1,3 +1,19 @@
1
+ exports.ActivityIndicatorView = require('./lib/activity-indicator-view')
2
+ exports.AttributedString = require('./lib/attributed-string')
3
+ exports.BezierPath = require('./lib/bezier-path')
4
+ exports.Color = require('./lib/color')
5
+ exports.Font = require('./lib/font')
6
+ exports.FontDescriptor = require('./lib/font-descriptor')
7
+ exports.Image = require('./lib/image')
8
+ exports.ImageView = require('./lib/image-view')
9
+ exports.Label = require('./lib/label')
10
+ exports.ParagraphStyle = require('./lib/paragraph-style')
11
+ exports.Scene = require('./lib/scene')
12
+ exports.Screen = require('./lib/screen')
13
+ exports.ScrollView = require('./lib/scroll-view')
14
+ exports.Switch = require('./lib/switch')
15
+ exports.TextField = require('./lib/text-field')
16
+ exports.TextView = require('./lib/text-view')
1
17
  exports.View = require('./lib/view')
2
18
  exports.ViewController = require('./lib/view-controller')
3
19
  exports.Window = require('./lib/window')
@@ -0,0 +1,29 @@
1
+ import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
2
+ import UIKitView = require('./view')
3
+ import UIKitColor = require('./color')
4
+
5
+ /** A spinning busy indicator, as a `UIActivityIndicatorView`. */
6
+ interface UIKitActivityIndicatorView extends UIKitView {
7
+ /** The size of the indicator, as a `STYLE` constant. */
8
+ style: number
9
+
10
+ get color(): UIKitColor | null
11
+ set color(color: Wrapper | null)
12
+
13
+ /** Whether the indicator is hidden while it is not spinning. */
14
+ hidesWhenStopped: boolean
15
+
16
+ /** Whether the indicator is spinning. */
17
+ animating: boolean
18
+ }
19
+
20
+ declare class UIKitActivityIndicatorView {
21
+ constructor(frame?: Partial<UIKitView.Rect>)
22
+
23
+ static readonly STYLE: {
24
+ readonly MEDIUM: number
25
+ readonly LARGE: number
26
+ }
27
+ }
28
+
29
+ export = UIKitActivityIndicatorView
@@ -0,0 +1,181 @@
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_activity_indicator_view_init(js_env_t *env, js_callback_info_t *info) {
11
+ int err;
12
+
13
+ size_t argc = 4;
14
+ js_value_t *argv[4];
15
+
16
+ bare_ui_kit_state_t *state;
17
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
18
+ assert(err == 0);
19
+
20
+ assert(argc == 4);
21
+
22
+ double x;
23
+ if (!bare_ui_kit__read_double(env, argv[0], "x", &x)) return NULL;
24
+
25
+ double y;
26
+ if (!bare_ui_kit__read_double(env, argv[1], "y", &y)) return NULL;
27
+
28
+ double width;
29
+ if (!bare_ui_kit__read_double(env, argv[2], "width", &width)) return NULL;
30
+
31
+ double height;
32
+ if (!bare_ui_kit__read_double(env, argv[3], "height", &height)) return NULL;
33
+
34
+ js_value_t *result;
35
+
36
+ @autoreleasepool {
37
+ UIActivityIndicatorView *handle = [[[UIActivityIndicatorView alloc]
38
+ initWithFrame:CGRectMake(x, y, width, height)] autorelease];
39
+
40
+ result = bare_foundation_bridge(env, state->registry, handle);
41
+ }
42
+
43
+ return result;
44
+ }
45
+
46
+ static js_value_t *
47
+ bare_ui_kit_activity_indicator_view_style(js_env_t *env, js_callback_info_t *info) {
48
+ int err;
49
+
50
+ size_t argc = 2;
51
+ js_value_t *argv[2];
52
+
53
+ bare_ui_kit_state_t *state;
54
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
55
+ assert(err == 0);
56
+
57
+ assert(argc == 1 || argc == 2);
58
+
59
+ void *handle;
60
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
61
+
62
+ js_value_t *result = NULL;
63
+
64
+ @autoreleasepool {
65
+ UIActivityIndicatorView *view = (__bridge UIActivityIndicatorView *) handle;
66
+
67
+ if (argc == 1) {
68
+ err = js_create_int32(env, (int32_t) view.activityIndicatorViewStyle, &result);
69
+ assert(err == 0);
70
+ } else {
71
+ int32_t style;
72
+ if (!bare_ui_kit__read_int32(env, argv[1], "style", &style)) return NULL;
73
+
74
+ view.activityIndicatorViewStyle = (UIActivityIndicatorViewStyle) style;
75
+ }
76
+ }
77
+
78
+ return result;
79
+ }
80
+
81
+ static js_value_t *
82
+ bare_ui_kit_activity_indicator_view_color(js_env_t *env, js_callback_info_t *info) {
83
+ int err;
84
+
85
+ size_t argc = 2;
86
+ js_value_t *argv[2];
87
+
88
+ bare_ui_kit_state_t *state;
89
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
90
+ assert(err == 0);
91
+
92
+ assert(argc == 1 || argc == 2);
93
+
94
+ void *handle;
95
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
96
+
97
+ js_value_t *result = NULL;
98
+
99
+ @autoreleasepool {
100
+ UIActivityIndicatorView *view = (__bridge UIActivityIndicatorView *) handle;
101
+
102
+ if (argc == 1) {
103
+ result = bare_foundation_bridge(env, state->registry, view.color);
104
+ } else {
105
+ view.color = bare_foundation_to_object(env, state->registry, argv[1]);
106
+ }
107
+ }
108
+
109
+ return result;
110
+ }
111
+
112
+ static js_value_t *
113
+ bare_ui_kit_activity_indicator_view_hides_when_stopped(js_env_t *env, js_callback_info_t *info) {
114
+ int err;
115
+
116
+ size_t argc = 2;
117
+ js_value_t *argv[2];
118
+
119
+ bare_ui_kit_state_t *state;
120
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
121
+ assert(err == 0);
122
+
123
+ assert(argc == 1 || argc == 2);
124
+
125
+ void *handle;
126
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
127
+
128
+ js_value_t *result = NULL;
129
+
130
+ @autoreleasepool {
131
+ UIActivityIndicatorView *view = (__bridge UIActivityIndicatorView *) handle;
132
+
133
+ if (argc == 1) {
134
+ err = js_get_boolean(env, view.hidesWhenStopped, &result);
135
+ assert(err == 0);
136
+ } else {
137
+ bool value;
138
+ if (!bare_ui_kit__read_bool(env, argv[1], "hidesWhenStopped", &value)) return NULL;
139
+
140
+ view.hidesWhenStopped = value;
141
+ }
142
+ }
143
+
144
+ return result;
145
+ }
146
+
147
+ static js_value_t *
148
+ bare_ui_kit_activity_indicator_view_animating(js_env_t *env, js_callback_info_t *info) {
149
+ int err;
150
+
151
+ size_t argc = 2;
152
+ js_value_t *argv[2];
153
+
154
+ bare_ui_kit_state_t *state;
155
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
156
+ assert(err == 0);
157
+
158
+ assert(argc == 1 || argc == 2);
159
+
160
+ void *handle;
161
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
162
+
163
+ js_value_t *result = NULL;
164
+
165
+ @autoreleasepool {
166
+ UIActivityIndicatorView *view = (__bridge UIActivityIndicatorView *) handle;
167
+
168
+ if (argc == 1) {
169
+ err = js_get_boolean(env, view.animating, &result);
170
+ assert(err == 0);
171
+ } else {
172
+ bool value;
173
+ if (!bare_ui_kit__read_bool(env, argv[1], "animating", &value)) return NULL;
174
+
175
+ if (value) [view startAnimating];
176
+ else [view stopAnimating];
177
+ }
178
+ }
179
+
180
+ return result;
181
+ }
@@ -0,0 +1,56 @@
1
+ const binding = require('../binding')
2
+ const { adopt } = require('./handle')
3
+ const wrap = require('./wrap')
4
+ const UIKitColor = require('./color')
5
+ const UIKitView = require('./view')
6
+
7
+ module.exports = exports = class UIKitActivityIndicatorView extends UIKitView {
8
+ _init(opts) {
9
+ const { x = 0, y = 0, width = 0, height = 0 } = opts
10
+
11
+ return binding.activityIndicatorViewInit(x, y, width, height)
12
+ }
13
+
14
+ get style() {
15
+ return binding.activityIndicatorViewStyle(this._tag)
16
+ }
17
+
18
+ set style(value) {
19
+ binding.activityIndicatorViewStyle(this._tag, value)
20
+ }
21
+
22
+ get color() {
23
+ return wrap(UIKitColor, binding.activityIndicatorViewColor(this._tag))
24
+ }
25
+
26
+ set color(value) {
27
+ binding.activityIndicatorViewColor(this._tag, value === null ? null : adopt(value))
28
+ }
29
+
30
+ get hidesWhenStopped() {
31
+ return binding.activityIndicatorViewHidesWhenStopped(this._tag)
32
+ }
33
+
34
+ set hidesWhenStopped(value) {
35
+ binding.activityIndicatorViewHidesWhenStopped(this._tag, value)
36
+ }
37
+
38
+ get animating() {
39
+ return binding.activityIndicatorViewAnimating(this._tag)
40
+ }
41
+
42
+ set animating(value) {
43
+ binding.activityIndicatorViewAnimating(this._tag, value)
44
+ }
45
+
46
+ [Symbol.for('bare.inspect')]() {
47
+ return {
48
+ __proto__: { constructor: UIKitActivityIndicatorView }
49
+ }
50
+ }
51
+ }
52
+
53
+ exports.STYLE = {
54
+ MEDIUM: binding.ACTIVITY_INDICATOR_VIEW_STYLE_MEDIUM,
55
+ LARGE: binding.ACTIVITY_INDICATOR_VIEW_STYLE_LARGE
56
+ }
@@ -0,0 +1,33 @@
1
+ import EventEmitter from 'bare-events'
2
+ import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
3
+
4
+ /** A button in an alert, as a `UIAlertAction`. */
5
+ interface UIKitAlertAction extends EventEmitter<UIKitAlertAction.Events> {
6
+ readonly title: string | null
7
+
8
+ readonly style: number
9
+
10
+ readonly [tag]: number
11
+
12
+ readonly [handle]: Handle
13
+ }
14
+
15
+ declare class UIKitAlertAction {
16
+ /** `style` is a `STYLE` constant and defaults to `STYLE.DEFAULT`. */
17
+ constructor(opts?: { title?: string; style?: number })
18
+
19
+ static readonly STYLE: {
20
+ readonly DEFAULT: number
21
+ readonly CANCEL: number
22
+ readonly DESTRUCTIVE: number
23
+ }
24
+ }
25
+
26
+ declare namespace UIKitAlertAction {
27
+ export interface Events {
28
+ /** The button was pressed. */
29
+ selected: []
30
+ }
31
+ }
32
+
33
+ export = UIKitAlertAction
@@ -0,0 +1,48 @@
1
+ const EventEmitter = require('bare-events')
2
+ const binding = require('../binding')
3
+ const registry = require('bare-foundation-registry')
4
+
5
+ // No mask: the handler is set when the action is made, so it always reports.
6
+ module.exports = exports = class UIKitAlertAction extends EventEmitter {
7
+ constructor(opts = {}) {
8
+ super()
9
+
10
+ const { tag = null, title = '', style = exports.STYLE.DEFAULT } = opts
11
+
12
+ this._tag = tag === null ? binding.alertActionInit(title, style, this) : tag
13
+
14
+ this._token = binding.claim(this._tag, this)
15
+ }
16
+
17
+ get [registry.tag]() {
18
+ return this._tag
19
+ }
20
+
21
+ get [registry.handle]() {
22
+ return binding.handle(this._tag)
23
+ }
24
+
25
+ get title() {
26
+ return binding.alertActionTitle(this._tag)
27
+ }
28
+
29
+ get style() {
30
+ return binding.alertActionStyle(this._tag)
31
+ }
32
+
33
+ _onselected() {
34
+ this.emit('selected')
35
+ }
36
+
37
+ [Symbol.for('bare.inspect')]() {
38
+ return {
39
+ __proto__: { constructor: UIKitAlertAction }
40
+ }
41
+ }
42
+ }
43
+
44
+ exports.STYLE = {
45
+ DEFAULT: binding.ALERT_ACTION_STYLE_DEFAULT,
46
+ CANCEL: binding.ALERT_ACTION_STYLE_CANCEL,
47
+ DESTRUCTIVE: binding.ALERT_ACTION_STYLE_DESTRUCTIVE
48
+ }
@@ -0,0 +1,20 @@
1
+ import UIKitViewController = require('./view-controller')
2
+ import UIKitAlertAction = require('./alert-action')
3
+
4
+ /** An alert or action sheet, as a `UIAlertController`. Show it with `present()`. */
5
+ interface UIKitAlertController extends UIKitViewController {
6
+ /** Add a button. Listen for its `selected` event to know when it is pressed. */
7
+ addAction(action: UIKitAlertAction): this
8
+ }
9
+
10
+ declare class UIKitAlertController {
11
+ /** `preferredStyle` is a `STYLE` constant and defaults to `STYLE.ALERT`. */
12
+ constructor(opts?: { title?: string; message?: string | null; preferredStyle?: number })
13
+
14
+ static readonly STYLE: {
15
+ readonly ACTION_SHEET: number
16
+ readonly ALERT: number
17
+ }
18
+ }
19
+
20
+ export = UIKitAlertController
@@ -0,0 +1,199 @@
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
+ // An action gets its handler when it is made, so it always reports and has no
10
+ // mask.
11
+ @interface BareAlertActionHandler : NSObject {
12
+ @public
13
+ js_env_t *env;
14
+ js_ref_t *ctx;
15
+ }
16
+ @end
17
+
18
+ @implementation BareAlertActionHandler
19
+
20
+ - (void)dealloc {
21
+ int err;
22
+
23
+ err = js_delete_reference(env, ctx);
24
+ assert(err == 0);
25
+
26
+ [super dealloc];
27
+ }
28
+
29
+ - (void)selected {
30
+ bare_ui_kit__emit(env, ctx, "_onselected");
31
+ }
32
+
33
+ @end
34
+
35
+ static js_value_t *
36
+ bare_ui_kit_alert_action_init(js_env_t *env, js_callback_info_t *info) {
37
+ int err;
38
+
39
+ size_t argc = 3;
40
+ js_value_t *argv[3];
41
+
42
+ bare_ui_kit_state_t *state;
43
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
44
+ assert(err == 0);
45
+
46
+ assert(argc == 3);
47
+
48
+ double style;
49
+ if (!bare_ui_kit__read_double(env, argv[1], "style", &style)) return NULL;
50
+
51
+ js_value_t *result;
52
+
53
+ @autoreleasepool {
54
+ NSString *title = bare_ui_kit__to_string(env, argv[0]);
55
+
56
+ BareAlertActionHandler *handler = [[BareAlertActionHandler alloc] init];
57
+
58
+ handler->env = env;
59
+
60
+ // Weak, so the native object does not keep its own wrapper alive.
61
+ err = js_create_reference(env, argv[2], 0, &handler->ctx);
62
+ assert(err == 0);
63
+
64
+ UIAlertAction *action = [UIAlertAction actionWithTitle:title
65
+ style:(UIAlertActionStyle) style
66
+ handler:^(UIAlertAction *selected) {
67
+ [handler selected];
68
+ }];
69
+
70
+ // The action owns the copied block, and the block retains what it captured,
71
+ // so the handler outlives this scope.
72
+ [handler release];
73
+
74
+ result = bare_foundation_bridge(env, state->registry, action);
75
+ }
76
+
77
+ return result;
78
+ }
79
+
80
+ static js_value_t *
81
+ bare_ui_kit_alert_action_title(js_env_t *env, js_callback_info_t *info) {
82
+ int err;
83
+
84
+ size_t argc = 1;
85
+ js_value_t *argv[1];
86
+
87
+ bare_ui_kit_state_t *state;
88
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
89
+ assert(err == 0);
90
+
91
+ assert(argc == 1);
92
+
93
+ void *handle;
94
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
95
+
96
+ js_value_t *result;
97
+
98
+ @autoreleasepool {
99
+ UIAlertAction *action = (__bridge UIAlertAction *) handle;
100
+
101
+ result = bare_ui_kit__from_string(env, action.title);
102
+ }
103
+
104
+ return result;
105
+ }
106
+
107
+ static js_value_t *
108
+ bare_ui_kit_alert_action_style(js_env_t *env, js_callback_info_t *info) {
109
+ int err;
110
+
111
+ size_t argc = 1;
112
+ js_value_t *argv[1];
113
+
114
+ bare_ui_kit_state_t *state;
115
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
116
+ assert(err == 0);
117
+
118
+ assert(argc == 1);
119
+
120
+ void *handle;
121
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
122
+
123
+ js_value_t *result;
124
+
125
+ @autoreleasepool {
126
+ UIAlertAction *action = (__bridge UIAlertAction *) handle;
127
+
128
+ err = js_create_int32(env, (int32_t) action.style, &result);
129
+ assert(err == 0);
130
+ }
131
+
132
+ return result;
133
+ }
134
+
135
+ static js_value_t *
136
+ bare_ui_kit_alert_controller_init(js_env_t *env, js_callback_info_t *info) {
137
+ int err;
138
+
139
+ size_t argc = 3;
140
+ js_value_t *argv[3];
141
+
142
+ bare_ui_kit_state_t *state;
143
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
144
+ assert(err == 0);
145
+
146
+ assert(argc == 3);
147
+
148
+ double style;
149
+ if (!bare_ui_kit__read_double(env, argv[2], "preferred_style", &style)) return NULL;
150
+
151
+ js_value_t *result;
152
+
153
+ @autoreleasepool {
154
+ NSString *title = bare_ui_kit__to_string(env, argv[0]);
155
+
156
+ js_value_t *message = argv[1];
157
+
158
+ js_value_type_t type;
159
+ err = js_typeof(env, message, &type);
160
+ assert(err == 0);
161
+
162
+ UIAlertController *controller =
163
+ [UIAlertController alertControllerWithTitle:title
164
+ message:type == js_string ? bare_ui_kit__to_string(env, message) : nil
165
+ preferredStyle:(UIAlertControllerStyle) style];
166
+
167
+ result = bare_foundation_bridge(env, state->registry, controller);
168
+ }
169
+
170
+ return result;
171
+ }
172
+
173
+ static js_value_t *
174
+ bare_ui_kit_alert_controller_add_action(js_env_t *env, js_callback_info_t *info) {
175
+ int err;
176
+
177
+ size_t argc = 2;
178
+ js_value_t *argv[2];
179
+
180
+ bare_ui_kit_state_t *state;
181
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
182
+ assert(err == 0);
183
+
184
+ assert(argc == 2);
185
+
186
+ void *handle;
187
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
188
+
189
+ void *action;
190
+ if (bare_foundation_read_tag(env, state->registry, argv[1], "action", &action) < 0) return NULL;
191
+
192
+ @autoreleasepool {
193
+ UIAlertController *controller = (__bridge UIAlertController *) handle;
194
+
195
+ [controller addAction:(__bridge UIAlertAction *) action];
196
+ }
197
+
198
+ return NULL;
199
+ }
@@ -0,0 +1,33 @@
1
+ const binding = require('../binding')
2
+ const { adopt } = require('./handle')
3
+ const UIKitViewController = require('./view-controller')
4
+
5
+ module.exports = exports = class UIKitAlertController extends UIKitViewController {
6
+ constructor(opts = {}) {
7
+ const { title = '', message = null, preferredStyle = exports.STYLE.ALERT } = opts
8
+
9
+ super({ tag: binding.alertControllerInit(title, message, preferredStyle) })
10
+
11
+ this._actions = new Set()
12
+ }
13
+
14
+ addAction(action) {
15
+ binding.alertControllerAddAction(this._tag, adopt(action))
16
+
17
+ // Keep the wrapper, so its listeners live as long as the controller.
18
+ this._actions.add(action)
19
+
20
+ return this
21
+ }
22
+
23
+ [Symbol.for('bare.inspect')]() {
24
+ return {
25
+ __proto__: { constructor: UIKitAlertController }
26
+ }
27
+ }
28
+ }
29
+
30
+ exports.STYLE = {
31
+ ACTION_SHEET: binding.ALERT_CONTROLLER_STYLE_ACTION_SHEET,
32
+ ALERT: binding.ALERT_CONTROLLER_STYLE_ALERT
33
+ }