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
@@ -6,10 +6,20 @@
6
6
 
7
7
  #import "bridging.h"
8
8
 
9
- @interface BareViewController : UIViewController {
9
+ // The controller lays its view out to fill the window, so this is where a size
10
+ // change is seen. Watching every view would report the same layout once per
11
+ // view.
12
+ enum {
13
+ bare_ui_kit_view_controller_event_did_layout_subviews = 1 << 0,
14
+ bare_ui_kit_view_controller_event_safe_area_insets_did_change = 1 << 1,
15
+ };
16
+
17
+ @interface BareViewController : UIViewController <BareEventTarget> {
10
18
  @public
11
19
  js_env_t *env;
12
20
  js_ref_t *ctx;
21
+
22
+ int32_t mask;
13
23
  }
14
24
 
15
25
  @end
@@ -25,6 +35,30 @@
25
35
  [super dealloc];
26
36
  }
27
37
 
38
+ - (int32_t)eventMask {
39
+ return mask;
40
+ }
41
+
42
+ - (void)setEventMask:(int32_t)value {
43
+ mask = value;
44
+ }
45
+
46
+ - (void)viewDidLayoutSubviews {
47
+ [super viewDidLayoutSubviews];
48
+
49
+ if ((mask & bare_ui_kit_view_controller_event_did_layout_subviews) == 0) return;
50
+
51
+ bare_ui_kit__emit(env, ctx, "_ondidlayoutsubviews");
52
+ }
53
+
54
+ - (void)viewSafeAreaInsetsDidChange {
55
+ [super viewSafeAreaInsetsDidChange];
56
+
57
+ if ((mask & bare_ui_kit_view_controller_event_safe_area_insets_did_change) == 0) return;
58
+
59
+ bare_ui_kit__emit(env, ctx, "_onsafeareainsetsdidchange");
60
+ }
61
+
28
62
  @end
29
63
 
30
64
  static js_value_t *
@@ -34,7 +68,8 @@ bare_ui_kit_view_controller_init(js_env_t *env, js_callback_info_t *info) {
34
68
  size_t argc = 1;
35
69
  js_value_t *argv[1];
36
70
 
37
- err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
71
+ bare_ui_kit_state_t *state;
72
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
38
73
  assert(err == 0);
39
74
 
40
75
  assert(argc == 1);
@@ -42,20 +77,82 @@ bare_ui_kit_view_controller_init(js_env_t *env, js_callback_info_t *info) {
42
77
  js_value_t *result;
43
78
 
44
79
  @autoreleasepool {
45
- BareViewController *handle = [[BareViewController alloc] init];
80
+ BareViewController *handle = [[[BareViewController alloc] init] autorelease];
46
81
 
47
- err = js_create_external(env, (void *) CFBridgingRetain(handle), bare_ui_kit__on_bridged_release, NULL, &result);
48
- assert(err == 0);
82
+ result = bare_foundation_bridge(env, state->registry, handle);
49
83
 
50
84
  handle->env = env;
51
85
 
52
- err = js_create_reference(env, argv[0], 1, &handle->ctx);
86
+ // Weak, so the native object does not keep its own wrapper alive. Events
87
+ // are dropped once the wrapper is collected.
88
+ err = js_create_reference(env, argv[0], 0, &handle->ctx);
53
89
  assert(err == 0);
54
90
  }
55
91
 
56
92
  return result;
57
93
  }
58
94
 
95
+ static js_value_t *
96
+ bare_ui_kit_view_controller_present(js_env_t *env, js_callback_info_t *info) {
97
+ int err;
98
+
99
+ size_t argc = 3;
100
+ js_value_t *argv[3];
101
+
102
+ bare_ui_kit_state_t *state;
103
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
104
+ assert(err == 0);
105
+
106
+ assert(argc == 3);
107
+
108
+ void *handle;
109
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
110
+
111
+ void *presented;
112
+ if (bare_foundation_read_tag(env, state->registry, argv[1], "presented", &presented) < 0) return NULL;
113
+
114
+ bool animated;
115
+ if (!bare_ui_kit__read_bool(env, argv[2], "animated", &animated)) return NULL;
116
+
117
+ @autoreleasepool {
118
+ UIViewController *controller = (__bridge UIViewController *) handle;
119
+
120
+ [controller presentViewController:(__bridge UIViewController *) presented
121
+ animated:animated
122
+ completion:nil];
123
+ }
124
+
125
+ return NULL;
126
+ }
127
+
128
+ static js_value_t *
129
+ bare_ui_kit_view_controller_dismiss(js_env_t *env, js_callback_info_t *info) {
130
+ int err;
131
+
132
+ size_t argc = 2;
133
+ js_value_t *argv[2];
134
+
135
+ bare_ui_kit_state_t *state;
136
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
137
+ assert(err == 0);
138
+
139
+ assert(argc == 2);
140
+
141
+ void *handle;
142
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
143
+
144
+ bool animated;
145
+ if (!bare_ui_kit__read_bool(env, argv[1], "animated", &animated)) return NULL;
146
+
147
+ @autoreleasepool {
148
+ UIViewController *controller = (__bridge UIViewController *) handle;
149
+
150
+ [controller dismissViewControllerAnimated:animated completion:nil];
151
+ }
152
+
153
+ return NULL;
154
+ }
155
+
59
156
  static js_value_t *
60
157
  bare_ui_kit_view_controller_view(js_env_t *env, js_callback_info_t *info) {
61
158
  int err;
@@ -63,14 +160,14 @@ bare_ui_kit_view_controller_view(js_env_t *env, js_callback_info_t *info) {
63
160
  size_t argc = 2;
64
161
  js_value_t *argv[2];
65
162
 
66
- err = js_get_callback_info(env, info, &argc, argv, NULL, NULL);
163
+ bare_ui_kit_state_t *state;
164
+ err = js_get_callback_info(env, info, &argc, argv, NULL, (void **) &state);
67
165
  assert(err == 0);
68
166
 
69
167
  assert(argc == 1 || argc == 2);
70
168
 
71
169
  void *handle;
72
- err = js_get_value_external(env, argv[0], &handle);
73
- assert(err == 0);
170
+ if (bare_foundation_read_tag(env, state->registry, argv[0], "handle", &handle) < 0) return NULL;
74
171
 
75
172
  js_value_t *result = NULL;
76
173
 
@@ -78,18 +175,9 @@ bare_ui_kit_view_controller_view(js_env_t *env, js_callback_info_t *info) {
78
175
  UIViewController *view_controller = (__bridge UIViewController *) handle;
79
176
 
80
177
  if (argc == 1) {
81
- UIView *view = view_controller.view;
82
-
83
- err = js_create_external(env, (void *) CFBridgingRetain(view), bare_ui_kit__on_bridged_release, NULL, &result);
84
- assert(err == 0);
178
+ result = bare_foundation_bridge(env, state->registry, view_controller.view);
85
179
  } else {
86
- void *handle;
87
- err = js_get_value_external(env, argv[1], &handle);
88
- assert(err == 0);
89
-
90
- UIView *view = (__bridge UIView *) handle;
91
-
92
- view_controller.view = view;
180
+ view_controller.view = bare_foundation_to_object(env, state->registry, argv[1]);
93
181
  }
94
182
  }
95
183
 
@@ -1,20 +1,60 @@
1
1
  const EventEmitter = require('bare-events')
2
2
  const binding = require('../binding')
3
+ const registry = require('bare-foundation-registry')
4
+ const { adopt } = require('./handle')
5
+ const observe = require('./events')
6
+ const retain = require('./retain')
3
7
  const UIKitView = require('./view')
4
8
 
5
- module.exports = class UIKitViewController extends EventEmitter {
6
- constructor(handle = null) {
9
+ module.exports = exports = class UIKitViewController extends EventEmitter {
10
+ constructor(opts = {}) {
7
11
  super()
8
12
 
9
- this._handle = handle || binding.viewControllerInit(this)
13
+ const { tag = null } = opts
14
+
15
+ this._tag = tag === null ? binding.viewControllerInit(this) : tag
16
+ this._view = null
17
+
18
+ this._token = binding.claim(this._tag, this)
19
+
20
+ observe(this)
21
+ }
22
+
23
+ get [registry.tag]() {
24
+ return this._tag
25
+ }
26
+
27
+ get [registry.handle]() {
28
+ return binding.handle(this._tag)
10
29
  }
11
30
 
12
31
  get view() {
13
- return new UIKitView(binding.viewControllerView(this._handle))
32
+ return retain(this, '_view', UIKitView, binding.viewControllerView(this._tag))
14
33
  }
15
34
 
16
35
  set view(view) {
17
- binding.viewControllerView(this._handle, view._handle)
36
+ binding.viewControllerView(this._tag, adopt(view))
37
+ this._view = view
38
+ }
39
+
40
+ present(controller, animated = true) {
41
+ binding.viewControllerPresent(this._tag, adopt(controller), animated)
42
+
43
+ return this
44
+ }
45
+
46
+ dismiss(animated = true) {
47
+ binding.viewControllerDismiss(this._tag, animated)
48
+
49
+ return this
50
+ }
51
+
52
+ _ondidlayoutsubviews() {
53
+ this.emit('didLayoutSubviews')
54
+ }
55
+
56
+ _onsafeareainsetsdidchange() {
57
+ this.emit('safeAreaInsetsDidChange')
18
58
  }
19
59
 
20
60
  [Symbol.for('bare.inspect')]() {
@@ -23,3 +63,8 @@ module.exports = class UIKitViewController extends EventEmitter {
23
63
  }
24
64
  }
25
65
  }
66
+
67
+ exports._events = {
68
+ didLayoutSubviews: binding.VIEW_CONTROLLER_EVENT_DID_LAYOUT_SUBVIEWS,
69
+ safeAreaInsetsDidChange: binding.VIEW_CONTROLLER_EVENT_SAFE_AREA_INSETS_DID_CHANGE
70
+ }
package/lib/view.d.ts ADDED
@@ -0,0 +1,158 @@
1
+ import EventEmitter from 'bare-events'
2
+ import { tag, handle, Handle, Wrapper } from 'bare-foundation-registry'
3
+ import UIKitColor = require('./color')
4
+
5
+ /**
6
+ * The base of every view, as a `UIView`. Views that are added to a view are kept alive by it, so
7
+ * their listeners keep working.
8
+ */
9
+ interface UIKitView<
10
+ M extends Record<keyof M, unknown[]> = UIKitView.Events
11
+ > extends EventEmitter<M> {
12
+ /** The position and size of the view in its superview. Missing fields are 0. */
13
+ get frame(): UIKitView.Rect
14
+ set frame(frame: Partial<UIKitView.Rect>)
15
+
16
+ /** The position and size of the view in its own coordinates. Missing fields are 0. */
17
+ get bounds(): UIKitView.Rect
18
+ set bounds(bounds: Partial<UIKitView.Rect>)
19
+
20
+ hidden: boolean
21
+
22
+ /** How opaque the view is, from 0 to 1. */
23
+ alpha: number
24
+
25
+ /** How the content is fitted to the view, as a `CONTENT_MODE` constant. */
26
+ contentMode: number
27
+
28
+ clipsToBounds: boolean
29
+
30
+ userInteractionEnabled: boolean
31
+
32
+ get backgroundColor(): UIKitColor | null
33
+ set backgroundColor(color: Wrapper | null)
34
+
35
+ get tintColor(): UIKitColor | null
36
+ set tintColor(color: Wrapper | null)
37
+
38
+ /** How far the safe area is inset from each edge of the view. */
39
+ readonly safeAreaInsets: UIKitView.Insets
40
+
41
+ readonly superview: UIKitView | null
42
+
43
+ readonly subviews: UIKitView[]
44
+
45
+ /** Add `view` on top of the other subviews. It can come from another addon. */
46
+ addSubview(view: Wrapper): this
47
+
48
+ insertSubviewAtIndex(view: Wrapper, index: number): this
49
+
50
+ insertSubviewBelowSubview(view: Wrapper, sibling: Wrapper): this
51
+
52
+ insertSubviewAboveSubview(view: Wrapper, sibling: Wrapper): this
53
+
54
+ removeFromSuperview(): this
55
+
56
+ setNeedsLayout(): this
57
+
58
+ setNeedsDisplay(): this
59
+
60
+ /**
61
+ * Stop editing anywhere inside the view, which hides the keyboard. With `force`, the default,
62
+ * editing stops even if a field asks to keep it. Returns whether editing stopped.
63
+ */
64
+ endEditing(force?: boolean): boolean
65
+
66
+ /** Convert a point in the view to the coordinates of `view`, or of the window when `null`. */
67
+ convertPointToView(x: number, y: number, view?: UIKitView | null): { x: number; y: number }
68
+
69
+ /** Convert a point in `view`, or in the window when `null`, to the coordinates of the view. */
70
+ convertPointFromView(x: number, y: number, view?: UIKitView | null): { x: number; y: number }
71
+
72
+ /** The size the view would like to be, within `width` by `height`. */
73
+ sizeThatFits(width: number, height: number): { width: number; height: number }
74
+
75
+ /** Resize the view to the size it would like to be. */
76
+ sizeToFit(): this
77
+
78
+ /** Take the keyboard focus. Returns whether the view took it. */
79
+ becomeFirstResponder(): boolean
80
+
81
+ /** Give up the keyboard focus. Returns whether the view gave it up. */
82
+ resignFirstResponder(): boolean
83
+
84
+ /** Whether the view has the keyboard focus. */
85
+ readonly firstResponder: boolean
86
+
87
+ /** Force light or dark mode for the view, as a `USER_INTERFACE_STYLE` constant. */
88
+ overrideUserInterfaceStyle: number
89
+
90
+ /** Whether the view is drawn in light or dark mode, as a `USER_INTERFACE_STYLE` constant. */
91
+ readonly userInterfaceStyle: number
92
+
93
+ readonly [tag]: number
94
+
95
+ readonly [handle]: Handle
96
+ }
97
+
98
+ declare class UIKitView<M extends Record<keyof M, unknown[]> = UIKitView.Events> {
99
+ /** Create a view with `frame`. Missing fields are 0. */
100
+ constructor(frame?: Partial<UIKitView.Rect>)
101
+
102
+ static readonly USER_INTERFACE_STYLE: {
103
+ readonly UNSPECIFIED: number
104
+ readonly LIGHT: number
105
+ readonly DARK: number
106
+ }
107
+
108
+ static readonly CONTENT_MODE: {
109
+ readonly SCALE_TO_FILL: number
110
+ readonly SCALE_ASPECT_FIT: number
111
+ readonly SCALE_ASPECT_FILL: number
112
+ readonly REDRAW: number
113
+ readonly CENTER: number
114
+ readonly TOP: number
115
+ readonly BOTTOM: number
116
+ readonly LEFT: number
117
+ readonly RIGHT: number
118
+ readonly TOP_LEFT: number
119
+ readonly TOP_RIGHT: number
120
+ readonly BOTTOM_LEFT: number
121
+ readonly BOTTOM_RIGHT: number
122
+ }
123
+ }
124
+
125
+ declare namespace UIKitView {
126
+ export interface Rect {
127
+ x: number
128
+ y: number
129
+ width: number
130
+ height: number
131
+ }
132
+
133
+ export interface Insets {
134
+ top: number
135
+ left: number
136
+ bottom: number
137
+ right: number
138
+ }
139
+
140
+ /** A touch. `pointerId` tells fingers apart. */
141
+ export interface Touch {
142
+ x: number
143
+ y: number
144
+ pointerId: number
145
+ }
146
+
147
+ export interface Events {
148
+ touchesBegan: [touch: Touch]
149
+ touchesMoved: [touch: Touch]
150
+ touchesEnded: [touch: Touch]
151
+ touchesCancelled: [touch: Touch]
152
+
153
+ /** A trait changed, such as light or dark mode. */
154
+ traitChange: []
155
+ }
156
+ }
157
+
158
+ export = UIKitView