@ng-native/components 0.28.0 → 0.30.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 (123) hide show
  1. package/README.md +2 -2
  2. package/android/src/main/java/dev/ngnative/components/ColorSchemeModule.kt +116 -11
  3. package/dist/activity-indicator.js +3 -3
  4. package/dist/animated-style.js +3 -3
  5. package/dist/animations-web.js +3 -3
  6. package/dist/animations.js +3 -3
  7. package/dist/content-container.js +3 -3
  8. package/dist/context-menu.js +3 -3
  9. package/dist/drag-and-drop.js +6 -6
  10. package/dist/gestures-web.js +6 -6
  11. package/dist/gestures.js +6 -6
  12. package/dist/gradient-text.d.ts +1 -1
  13. package/dist/gradient-text.js +4 -4
  14. package/dist/gradient-text.js.map +1 -1
  15. package/dist/image-background.js +3 -3
  16. package/dist/image.js +3 -3
  17. package/dist/index.d.ts +3 -2
  18. package/dist/index.js +3 -2
  19. package/dist/index.js.map +1 -1
  20. package/dist/input-accessory-view.js +3 -3
  21. package/dist/keyboard-avoiding-view.js +3 -3
  22. package/dist/keyboard-dock.js +15 -15
  23. package/dist/markdown-blocks.d.ts +2 -1
  24. package/dist/markdown-blocks.js +22 -18
  25. package/dist/markdown-blocks.js.map +1 -1
  26. package/dist/markdown-columns.js +3 -3
  27. package/dist/markdown-stream.js +8 -5
  28. package/dist/markdown-stream.js.map +1 -1
  29. package/dist/markdown.js +5 -5
  30. package/dist/markdown.js.map +1 -1
  31. package/dist/menu.d.ts +11 -5
  32. package/dist/menu.js +24 -44
  33. package/dist/menu.js.map +1 -1
  34. package/dist/modal.js +8 -3
  35. package/dist/modal.js.map +1 -1
  36. package/dist/native-button.d.ts +25 -3
  37. package/dist/native-button.js +102 -8
  38. package/dist/native-button.js.map +1 -1
  39. package/dist/native-gesture.js +3 -3
  40. package/dist/native-ref.js +3 -3
  41. package/dist/press-menu.d.ts +38 -8
  42. package/dist/press-menu.js +80 -19
  43. package/dist/press-menu.js.map +1 -1
  44. package/dist/pressable.js +14 -13
  45. package/dist/pressable.js.map +1 -1
  46. package/dist/reanimated-web.js +6 -6
  47. package/dist/reanimated.js +6 -6
  48. package/dist/refresh-control.js +3 -3
  49. package/dist/safe-area-provider.js +3 -3
  50. package/dist/safe-area-view.js +3 -3
  51. package/dist/scroll-view-props.js +3 -3
  52. package/dist/scroll-view.d.ts +3 -1
  53. package/dist/scroll-view.js +10 -5
  54. package/dist/scroll-view.js.map +1 -1
  55. package/dist/section-list.d.ts +4 -4
  56. package/dist/section-list.js +37 -34
  57. package/dist/section-list.js.map +1 -1
  58. package/dist/shortcut.js +3 -3
  59. package/dist/sidebar-item.js +3 -3
  60. package/dist/sidebar-section.d.ts +12 -5
  61. package/dist/sidebar-section.js +32 -12
  62. package/dist/sidebar-section.js.map +1 -1
  63. package/dist/sidebar.d.ts +11 -3
  64. package/dist/sidebar.js +18 -8
  65. package/dist/sidebar.js.map +1 -1
  66. package/dist/split-view.d.ts +23 -2
  67. package/dist/split-view.js +36 -9
  68. package/dist/split-view.js.map +1 -1
  69. package/dist/stand-ins/animations.js +3 -3
  70. package/dist/sticky-headers.d.ts +19 -0
  71. package/dist/sticky-headers.js +67 -10
  72. package/dist/sticky-headers.js.map +1 -1
  73. package/dist/sticky-rows.d.ts +13 -11
  74. package/dist/sticky-rows.js +35 -21
  75. package/dist/sticky-rows.js.map +1 -1
  76. package/dist/svg-icon.d.ts +16 -2
  77. package/dist/svg-icon.js +19 -3
  78. package/dist/svg-icon.js.map +1 -1
  79. package/dist/switch.js +3 -3
  80. package/dist/template-slot.js +3 -3
  81. package/dist/text-input.js +3 -3
  82. package/dist/text.js +3 -3
  83. package/dist/touchable-opacity.js +3 -3
  84. package/dist/tray-icon.d.ts +7 -1
  85. package/dist/tray-icon.js +17 -5
  86. package/dist/tray-icon.js.map +1 -1
  87. package/dist/view-base.d.ts +18 -2
  88. package/dist/view-base.js +42 -10
  89. package/dist/view-base.js.map +1 -1
  90. package/dist/view.js +3 -3
  91. package/dist/virtual-list-layout.d.ts +5 -0
  92. package/dist/virtual-list-layout.js.map +1 -1
  93. package/dist/virtual-list-num-columns.d.ts +8 -4
  94. package/dist/virtual-list-num-columns.js +13 -5
  95. package/dist/virtual-list-num-columns.js.map +1 -1
  96. package/dist/virtual-list-sticky-level.d.ts +0 -6
  97. package/dist/virtual-list-sticky-level.js +5 -29
  98. package/dist/virtual-list-sticky-level.js.map +1 -1
  99. package/dist/virtual-list.d.ts +72 -11
  100. package/dist/virtual-list.js +285 -74
  101. package/dist/virtual-list.js.map +1 -1
  102. package/dist/visual-effect.d.ts +37 -0
  103. package/dist/visual-effect.js +60 -0
  104. package/dist/visual-effect.js.map +1 -0
  105. package/dist/worklet-scroll.js +3 -3
  106. package/dist/worklet-style.js +3 -3
  107. package/dist/written-props.js +9 -0
  108. package/dist/written-props.js.map +1 -1
  109. package/ios/NgNativeButtonComponentView.mm +8 -4
  110. package/ios/NgNativeButtonMetrics.h +9 -2
  111. package/ios/NgNativeButtonMetrics.mm +33 -4
  112. package/ios/NgNativeButtonShadowNode.h +2 -0
  113. package/ios/NgNativeButtonShadowNode.mm +5 -1
  114. package/ios/NgNativeComponents.podspec +2 -2
  115. package/ios/NgNativeKeyboardFocus.h +21 -0
  116. package/ios/NgNativeKeyboardFocus.mm +28 -0
  117. package/ios/NgNativeKeyboardFocusModule.mm +203 -0
  118. package/ios/NgNativeMenus.mm +62 -2
  119. package/ios/NgNativePressMenu.h +36 -0
  120. package/ios/NgNativePressMenu.mm +79 -0
  121. package/ios/NgNativeViewBinder.h +5 -0
  122. package/ios/NgNativeViewBinder.mm +31 -4
  123. package/package.json +6 -6
@@ -1,4 +1,5 @@
1
- import type { ControlSize } from '@ng-native/device';
1
+ import { type ControlSize } from '@ng-native/device';
2
+ import { type ImageURISource } from './image.ts';
2
3
  import { ControlBase } from './pressable.ts';
3
4
  import * as i0 from "@angular/core";
4
5
  /**
@@ -8,8 +9,9 @@ import * as i0 from "@angular/core";
8
9
  export type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';
9
10
  /**
10
11
  * A button's picture, as on `<native-tab>`: an SF Symbol on Apple's OSes, a drawable on Android, or
11
- * an icon's SVG markup, such as an `@ng-icons` set's, on macOS and Linux. The host draws the markup
12
- * in the button's text colour, as it does a symbol, and an SF Symbol given too wins on macOS.
12
+ * an icon's SVG markup, such as an `@ng-icons` set's. macOS and Linux draw the markup themselves,
13
+ * and iOS and Android draw it through the renderer `SVG_ICON_RENDERER` provides. It is drawn in the
14
+ * button's text colour, as a symbol is, and an SF Symbol given too wins on macOS.
13
15
  */
14
16
  export type ButtonIcon = {
15
17
  readonly sfSymbol: string;
@@ -45,7 +47,27 @@ export declare class NativeButton extends ControlBase {
45
47
  readonly icon: import("@angular/core").InputSignal<ButtonIcon | undefined>;
46
48
  protected readonly symbol: import("@angular/core").Signal<string | undefined>;
47
49
  protected readonly drawableResource: import("@angular/core").Signal<string | undefined>;
50
+ private readonly svgRenderer;
51
+ private readonly svgHost;
52
+ private readonly errors;
53
+ protected readonly android: boolean;
54
+ /** Where the markup is drawn here, by the app's renderer, as an image. */
55
+ private readonly drawsSvg;
48
56
  protected readonly svgIcon: import("@angular/core").Signal<string | undefined>;
57
+ /** The markup drawn as an image, on iOS and Android, once the renderer has answered. */
58
+ private readonly drawnSvg;
59
+ /** The image iOS draws before the title, tinted as a symbol is. */
60
+ protected readonly iosPicture: import("@angular/core").Signal<ImageURISource | undefined>;
61
+ /** Android: the image before the label, a drawable's or the drawn markup. */
62
+ protected readonly androidPicture: import("@angular/core").Signal<ImageURISource | undefined>;
63
+ /** The label's colour, which an Android icon is tinted in: black, as text is, where none is set. */
64
+ protected readonly tint: import("@angular/core").WritableSignal<string | undefined>;
65
+ constructor();
66
+ /**
67
+ * The markup drawn once by the app's renderer, where the platform draws no SVG itself. An answer
68
+ * for an icon the button no longer has is dropped.
69
+ */
70
+ private drawSvg;
49
71
  /**
50
72
  * Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
51
73
  * it twice.
@@ -1,8 +1,19 @@
1
- import { Component, computed, forwardRef, input } from '@angular/core';
1
+ import { Component, ErrorHandler, ViewContainerRef, computed, effect, forwardRef, inject, input, signal, } from '@angular/core';
2
2
  import { isApplePlatform, nativePlatform, registerViewName, } from '@ng-native/fabric';
3
+ import { SVG_ICON_RENDERER } from '@ng-native/device';
4
+ import { Image } from "./image.js";
3
5
  import { ControlBase, TouchableBase } from "./pressable.js";
4
6
  import { svgIconMarkup } from "./svg-icon.js";
5
7
  import * as i0 from "@angular/core";
8
+ /** Platforms already told that a button's SVG icon has nothing to draw it. */
9
+ const warnedNoRenderer = new Set();
10
+ /**
11
+ * The side of an SVG icon drawn for iOS, in points. The button sizes it to its title's font, so
12
+ * it is drawn large enough for the largest text size to scale it down rather than up.
13
+ */
14
+ const IOS_SVG_SIZE = 40;
15
+ /** The side of an Android button's icon, in points: Material's for an icon in a button. */
16
+ const ANDROID_ICON_SIZE = 18;
6
17
  /**
7
18
  * The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no
8
19
  * platform button React Native draws, so there it is a view this component makes pressable.
@@ -47,8 +58,66 @@ export class NativeButton extends ControlBase {
47
58
  return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);
48
59
  }, /* @ts-ignore */
49
60
  ...(ngDevMode ? [{ debugName: "drawableResource" }] : /* istanbul ignore next */ []));
50
- svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', true), /* @ts-ignore */
61
+ svgRenderer = inject(SVG_ICON_RENDERER);
62
+ svgHost = inject(ViewContainerRef);
63
+ errors = inject(ErrorHandler);
64
+ android = nativePlatform() === 'android';
65
+ /** Where the markup is drawn here, by the app's renderer, as an image. */
66
+ drawsSvg = this.android || nativePlatform() === 'ios';
67
+ svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', !this.drawsSvg, 'macOS, Linux, iOS and Android'), /* @ts-ignore */
51
68
  ...(ngDevMode ? [{ debugName: "svgIcon" }] : /* istanbul ignore next */ []));
69
+ /** The markup drawn as an image, on iOS and Android, once the renderer has answered. */
70
+ drawnSvg = this.drawSvg();
71
+ /** The image iOS draws before the title, tinted as a symbol is. */
72
+ iosPicture = computed(() => this.android ? undefined : this.drawnSvg(), /* @ts-ignore */
73
+ ...(ngDevMode ? [{ debugName: "iosPicture" }] : /* istanbul ignore next */ []));
74
+ /** Android: the image before the label, a drawable's or the drawn markup. */
75
+ androidPicture = computed(() => {
76
+ if (!this.android)
77
+ return undefined;
78
+ const drawable = this.drawableResource();
79
+ if (drawable)
80
+ return { uri: drawable };
81
+ return this.drawnSvg();
82
+ }, /* @ts-ignore */
83
+ ...(ngDevMode ? [{ debugName: "androidPicture" }] : /* istanbul ignore next */ []));
84
+ /** The label's colour, which an Android icon is tinted in: black, as text is, where none is set. */
85
+ tint = signal(undefined, /* @ts-ignore */
86
+ ...(ngDevMode ? [{ debugName: "tint" }] : /* istanbul ignore next */ []));
87
+ constructor() {
88
+ super();
89
+ // Only a button with an icon follows its colour: a watch is a look at every commit.
90
+ effect((onCleanup) => {
91
+ if (!this.androidPicture())
92
+ return;
93
+ const follow = (colour) => this.tint.set(colour ?? 'black');
94
+ follow(this.engine.colour(this.node));
95
+ onCleanup(this.engine.watchColour(this.node, follow));
96
+ });
97
+ }
98
+ /**
99
+ * The markup drawn once by the app's renderer, where the platform draws no SVG itself. An answer
100
+ * for an icon the button no longer has is dropped.
101
+ */
102
+ drawSvg() {
103
+ const drawn = signal(undefined, /* @ts-ignore */
104
+ ...(ngDevMode ? [{ debugName: "drawn" }] : /* istanbul ignore next */ []));
105
+ if (!this.drawsSvg)
106
+ return drawn;
107
+ effect((onCleanup) => {
108
+ const markup = this.svgIcon();
109
+ drawn.set(undefined);
110
+ if (!markup)
111
+ return;
112
+ if (!this.svgRenderer)
113
+ return warnNoRenderer();
114
+ let current = true;
115
+ onCleanup(() => (current = false));
116
+ const size = this.android ? ANDROID_ICON_SIZE : IOS_SVG_SIZE;
117
+ this.svgRenderer.render(markup, size, this.svgHost).then((source) => current && drawn.set(source ?? undefined), (error) => this.errors.handleError(error));
118
+ });
119
+ return drawn;
120
+ }
52
121
  /**
53
122
  * Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press
54
123
  * it twice.
@@ -84,23 +153,48 @@ export class NativeButton extends ControlBase {
84
153
  super.ngOnDestroy();
85
154
  this.stopPress?.();
86
155
  }
87
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, deps: null, target: i0.ɵɵFactoryTarget.Component });
88
- static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.1.0", version: "22.2.0", type: NativeButton, isStandalone: true, selector: "native-button", inputs: { kind: { classPropertyName: "kind", publicName: "kind", isSignal: true, isRequired: false, transformFunction: null }, controlSize: { classPropertyName: "controlSize", publicName: "controlSize", isSignal: true, isRequired: false, transformFunction: null }, sfSymbol: { classPropertyName: "sfSymbol", publicName: "sfSymbol", isSignal: true, isRequired: false, transformFunction: null }, drawableName: { classPropertyName: "drawableName", publicName: "drawable", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "kind": "kind()", "controlSize": "controlSize()", "sfSymbol": "symbol()", "drawable": "drawableResource()", "svgIcon": "svgIcon()", "enabled": "!pressDisabled()" } }, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }], usesInheritance: true, ngImport: i0, template: '<ng-content />', isInline: true });
156
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeButton, deps: [], target: i0.ɵɵFactoryTarget.Component });
157
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "22.3.0", type: NativeButton, isStandalone: true, selector: "native-button", inputs: { kind: { classPropertyName: "kind", publicName: "kind", isSignal: true, isRequired: false, transformFunction: null }, controlSize: { classPropertyName: "controlSize", publicName: "controlSize", isSignal: true, isRequired: false, transformFunction: null }, sfSymbol: { classPropertyName: "sfSymbol", publicName: "sfSymbol", isSignal: true, isRequired: false, transformFunction: null }, drawableName: { classPropertyName: "drawableName", publicName: "drawable", isSignal: true, isRequired: false, transformFunction: null }, icon: { classPropertyName: "icon", publicName: "icon", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "kind": "kind()", "controlSize": "controlSize()", "sfSymbol": "symbol()", "drawable": "android ? undefined : drawableResource()", "svgIcon": "svgIcon()", "iconImage": "iosPicture()?.uri", "style.flexDirection": "androidPicture() ? \"row\" : undefined", "style.alignItems": "androidPicture() ? \"center\" : undefined", "style.gap": "androidPicture() ? \"8px\" : undefined", "enabled": "!pressDisabled()" } }, providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }], usesInheritance: true, ngImport: i0, template: `
158
+ @if (androidPicture(); as source) {
159
+ <image [source]="source" [tintColor]="tint()" style="width: 18px; height: 18px" />
160
+ }
161
+ <ng-content />
162
+ `, isInline: true, dependencies: [{ kind: "directive", type: Image, selector: "image", inputs: ["source", "src", "srcSet", "defaultSource", "loadingIndicatorSource", "resizeMode", "resizeMethod", "resizeMultiplier", "blurRadius", "capInsets", "tintColor", "fadeDuration", "progressiveRenderingEnabled", "alt", "crossOrigin", "referrerPolicy"] }] });
89
163
  }
90
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeButton, decorators: [{
164
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeButton, decorators: [{
91
165
  type: Component,
92
166
  args: [{
93
167
  selector: 'native-button',
94
- template: '<ng-content />',
168
+ imports: [Image],
169
+ template: `
170
+ @if (androidPicture(); as source) {
171
+ <image [source]="source" [tintColor]="tint()" style="width: 18px; height: 18px" />
172
+ }
173
+ <ng-content />
174
+ `,
95
175
  providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }],
96
176
  host: {
97
177
  '[kind]': 'kind()',
98
178
  '[controlSize]': 'controlSize()',
99
179
  '[sfSymbol]': 'symbol()',
100
- '[drawable]': 'drawableResource()',
180
+ '[drawable]': 'android ? undefined : drawableResource()',
101
181
  '[svgIcon]': 'svgIcon()',
182
+ '[iconImage]': 'iosPicture()?.uri',
183
+ '[style.flexDirection]': 'androidPicture() ? "row" : undefined',
184
+ '[style.alignItems]': 'androidPicture() ? "center" : undefined',
185
+ '[style.gap]': 'androidPicture() ? "8px" : undefined',
102
186
  '[enabled]': '!pressDisabled()',
103
187
  },
104
188
  }]
105
- }], propDecorators: { kind: [{ type: i0.Input, args: [{ isSignal: true, alias: "kind", required: false }] }], controlSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlSize", required: false }] }], sfSymbol: [{ type: i0.Input, args: [{ isSignal: true, alias: "sfSymbol", required: false }] }], drawableName: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawable", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }] } });
189
+ }], ctorParameters: () => [], propDecorators: { kind: [{ type: i0.Input, args: [{ isSignal: true, alias: "kind", required: false }] }], controlSize: [{ type: i0.Input, args: [{ isSignal: true, alias: "controlSize", required: false }] }], sfSymbol: [{ type: i0.Input, args: [{ isSignal: true, alias: "sfSymbol", required: false }] }], drawableName: [{ type: i0.Input, args: [{ isSignal: true, alias: "drawable", required: false }] }], icon: [{ type: i0.Input, args: [{ isSignal: true, alias: "icon", required: false }] }] } });
190
+ /** Says once, in development, that a button's SVG icon has nothing to draw it, so it shows none. */
191
+ function warnNoRenderer() {
192
+ const os = nativePlatform();
193
+ if ((typeof ngDevMode !== 'undefined' && !ngDevMode) || warnedNoRenderer.has(os))
194
+ return;
195
+ warnedNoRenderer.add(os);
196
+ console.warn(`[angular-native] <native-button> has an SVG icon and nothing to draw it on ${os}, so it ` +
197
+ `shows none. Add withSvgIcons(SvgImages) to provideNativeRouter (withSvgIcons from ` +
198
+ `@ng-native/router, SvgImages from @ng-native/icons), or provide SVG_ICON_RENDERER.`);
199
+ }
106
200
  //# sourceMappingURL=native-button.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"native-button.js","sourceRoot":"","sources":["../src/native-button.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,UAAU,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACvE,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GAEjB,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;;AAgB9C;;;GAGG;AACH,gBAAgB,CACd,eAAe,EACf,EAAE,GAAG,EAAE,gBAAgB,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,gBAAgB,EAAE,EACnE,SAAS,EACT,EAAE,WAAW,EAAE,OAAO,EAAE,CACzB,CAAC;AAEF;;;;;;;;;;GAUG;AAcH,MAAM,OAAO,YAAa,SAAQ,WAAW;IAC3C;;;OAGG;IACM,IAAI,GAAG,KAAK;wFAAc,CAAC;IACpC,yFAAyF;IAChF,WAAW,GAAG,KAAK;+FAAe,CAAC;IAC5C,uDAAuD;IAC9C,QAAQ,GAAG,KAAK;4FAAU,CAAC;IACpC,qDAAqD;IAC5C,YAAY,GAAG,KAAK,CAAS,SAAS,oFAAI,KAAK,EAAE,UAAU,GAAG,CAAC;IACxE,6DAA6D;IACpD,IAAI,GAAG,KAAK;wFAAc,CAAC;IAEjB,MAAM,GAAG,QAAQ,CAAC,GAAG,EAAE;QACxC,MAAM,IAAI,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,OAAO,IAAI,CAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,IAAI,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACr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E,KAAc,EAAE,OAAO,CAAC,CAAC;QAClE,CAAC,CACF,CAAC;IACJ,CAAC;IAEQ,WAAW;QAClB,KAAK,CAAC,WAAW,EAAE,CAAC;QACpB,IAAI,CAAC,SAAS,EAAE,EAAE,CAAC;IACrB,CAAC;uGAtEU,YAAY;2FAAZ,YAAY,m4BAVZ,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,CAAC,YAAY,CAAC,EAAE,CAAC,iDAD1E,gBAAgB;;2FAWf,YAAY;kBAbxB,SAAS;mBAAC;oBACT,QAAQ,EAAE,eAAe;oBACzB,QAAQ,EAAE,gBAAgB;oBAC1B,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;oBACpF,IAAI,EAAE;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,eAAe,EAAE,eAAe;wBAChC,YAAY,EAAE,UAAU;wBACxB,YAAY,EAAE,oBAAoB;wBAClC,WAAW,EAAE,WAAW;wBACxB,WAAW,EAAE,kBAAkB;qBAChC;iBACF","sourcesContent":["import { Component, computed, forwardRef, input } from '@angular/core';\nimport {\n isApplePlatform,\n nativePlatform,\n registerViewName,\n type HostNode,\n} from '@ng-native/fabric';\nimport type { ControlSize } from '@ng-native/device';\nimport { ControlBase, TouchableBase } from './pressable.ts';\nimport { svgIconMarkup } from './svg-icon.ts';\n\n/**\n * What a button does in its window: on macOS, Return presses `default` and Escape presses `cancel`.\n * On iOS they are styles only.\n */\nexport type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';\n\n/**\n * A button's picture, as on `<native-tab>`: an SF Symbol on Apple's OSes, a drawable on Android, or\n * an icon's SVG markup, such as an `@ng-icons` set's, on macOS and Linux. The host draws the markup\n * in the button's text colour, as it does a symbol, and an SF Symbol given too wins on macOS.\n */\nexport type ButtonIcon =\n { readonly sfSymbol: string } | { readonly drawable: string } | { readonly svg: string };\n\n/**\n * The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no\n * platform button React Native draws, so there it is a view this component makes pressable.\n */\nregisterViewName(\n 'native-button',\n { ios: 'NgNativeButton', android: 'View', macos: 'NgNativeButton' },\n undefined,\n { textContent: 'title' },\n);\n\n/**\n * A platform button, its label the text inside it:\n *\n * <native-button kind=\"default\" (press)=\"save()\">Save</native-button>\n *\n * On macOS it is an NSButton, on Linux a GtkButton and on iOS a UIButton, drawn by the host, which sends\n * `topButtonPress` when it is clicked, tapped, or pressed by Space, and on macOS by Return (a\n * `default` button) or Escape (a `cancel` one). On Android it is a view pressed through the responder, as a\n * `<pressable>` is, and takes `android_ripple` as one does. The web host draws an HTML `button`.\n * It is a button to assistive technology everywhere, and takes focus.\n */\n@Component({\n selector: 'native-button',\n template: '<ng-content />',\n providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }],\n host: {\n '[kind]': 'kind()',\n '[controlSize]': 'controlSize()',\n '[sfSymbol]': 'symbol()',\n '[drawable]': 'drawableResource()',\n '[svgIcon]': 'svgIcon()',\n '[enabled]': '!pressDisabled()',\n },\n})\nexport class NativeButton extends ControlBase {\n /**\n * What the button does in its window. In a desktop window `default` takes Return and `cancel`\n * takes Escape; elsewhere the kind is a style alone. Unset, it is a plain push button.\n */\n readonly kind = input<ButtonKind>();\n /** AppKit's control size on macOS, and UIKit's button size on iOS. Ignored elsewhere. */\n readonly controlSize = input<ControlSize>();\n /** An SF Symbol beside the label, on iOS and macOS. */\n readonly sfSymbol = input<string>();\n /** Android: a drawable resource beside the label. */\n readonly drawableName = input<string>(undefined, { alias: 'drawable' });\n /** The picture for each OS at once, as on `<native-tab>`. */\n readonly icon = input<ButtonIcon>();\n\n protected readonly symbol = computed(() => {\n const icon = this.icon();\n return this.sfSymbol() ?? (icon && 'sfSymbol' in icon ? icon.sfSymbol : undefined);\n });\n\n protected readonly drawableResource = computed(() => {\n const icon = this.icon();\n return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);\n });\n\n protected readonly svgIcon = computed(() => svgIconMarkup(this.icon(), 'native-button', true));\n\n /**\n * Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press\n * it twice.\n */\n private readonly drawnByHost = isApplePlatform() || nativePlatform() === 'linux';\n private stopPress: (() => void) | null = null;\n\n protected override roleByDefault(): 'button' {\n return 'button';\n }\n\n protected override accessibleByDefault(): boolean {\n return true;\n }\n\n protected override focusableByDefault(): boolean {\n return true;\n }\n\n protected override disabledForAccessibility(): boolean | undefined {\n return this.disabled();\n }\n\n protected override claims(): boolean {\n return !this.drawnByHost && super.claims();\n }\n\n override ngOnInit(): void {\n super.ngOnInit();\n if (!this.drawnByHost || this.stopPress) return;\n this.stopPress = this.engine.setEventListener(\n this.node as HostNode,\n 'topButtonPress',\n (event) => {\n if (this.pressDisabled()) return;\n this.emitReported(this.press, 'click', event as never, 'click');\n },\n );\n }\n\n override ngOnDestroy(): void {\n super.ngOnDestroy();\n this.stopPress?.();\n }\n}\n"]}
1
+ {"version":3,"file":"native-button.js","sourceRoot":"","sources":["../src/native-button.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,KAAK,EACL,MAAM,GACP,MAAM,eAAe,CAAC;AACvB,OAAO,EACL,eAAe,EACf,cAAc,EACd,gBAAgB,GAEjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,iBAAiB,EAAoB,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,KAAK,EAAuB,MAAM,YAAY,CAAC;AACxD,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAC5D,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;;AAI9C,8EAA8E;AAC9E,MAAM,gBAAgB,GAAG,IAAI,GAAG,EAAU,CAAC;AAE3C;;;G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O,EAAE,CAAC,KAAK,CAAC;oBAChB,QAAQ,EAAE;;;;;GAKT;oBACD,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,aAAa,CAAC,EAAE,CAAC;oBACpF,IAAI,EAAE;wBACJ,QAAQ,EAAE,QAAQ;wBAClB,eAAe,EAAE,eAAe;wBAChC,YAAY,EAAE,UAAU;wBACxB,YAAY,EAAE,0CAA0C;wBACxD,WAAW,EAAE,WAAW;wBACxB,aAAa,EAAE,mBAAmB;wBAClC,uBAAuB,EAAE,sCAAsC;wBAC/D,oBAAoB,EAAE,yCAAyC;wBAC/D,aAAa,EAAE,sCAAsC;wBACrD,WAAW,EAAE,kBAAkB;qBAChC;iBACF;;AAwID,oGAAoG;AACpG,SAAS,cAAc;IACrB,MAAM,EAAE,GAAG,cAAc,EAAE,CAAC;IAC5B,IAAI,CAAC,OAAO,SAAS,KAAK,WAAW,IAAI,CAAC,SAAS,CAAC,IAAI,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC;QAAE,OAAO;IACzF,gBAAgB,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACzB,OAAO,CAAC,IAAI,CACV,8EAA8E,EAAE,UAAU;QACxF,oFAAoF;QACpF,oFAAoF,CACvF,CAAC;AACJ,CAAC","sourcesContent":["import {\n Component,\n ErrorHandler,\n ViewContainerRef,\n computed,\n effect,\n forwardRef,\n inject,\n input,\n signal,\n} from '@angular/core';\nimport {\n isApplePlatform,\n nativePlatform,\n registerViewName,\n type HostNode,\n} from '@ng-native/fabric';\nimport { SVG_ICON_RENDERER, type ControlSize } from '@ng-native/device';\nimport { Image, type ImageURISource } from './image.ts';\nimport { ControlBase, TouchableBase } from './pressable.ts';\nimport { svgIconMarkup } from './svg-icon.ts';\n\ndeclare const ngDevMode: unknown;\n\n/** Platforms already told that a button's SVG icon has nothing to draw it. */\nconst warnedNoRenderer = new Set<string>();\n\n/**\n * The side of an SVG icon drawn for iOS, in points. The button sizes it to its title's font, so\n * it is drawn large enough for the largest text size to scale it down rather than up.\n */\nconst IOS_SVG_SIZE = 40;\n\n/** The side of an Android button's icon, in points: Material's for an icon in a button. */\nconst ANDROID_ICON_SIZE = 18;\n\n/**\n * What a button does in its window: on macOS, Return presses `default` and Escape presses `cancel`.\n * On iOS they are styles only.\n */\nexport type ButtonKind = 'default' | 'cancel' | 'destructive' | 'plain';\n\n/**\n * A button's picture, as on `<native-tab>`: an SF Symbol on Apple's OSes, a drawable on Android, or\n * an icon's SVG markup, such as an `@ng-icons` set's. macOS and Linux draw the markup themselves,\n * and iOS and Android draw it through the renderer `SVG_ICON_RENDERER` provides. It is drawn in the\n * button's text colour, as a symbol is, and an SF Symbol given too wins on macOS.\n */\nexport type ButtonIcon =\n { readonly sfSymbol: string } | { readonly drawable: string } | { readonly svg: string };\n\n/**\n * The button on Apple's OSes is the host's: NSButton on macOS and UIButton on iOS. Android has no\n * platform button React Native draws, so there it is a view this component makes pressable.\n */\nregisterViewName(\n 'native-button',\n { ios: 'NgNativeButton', android: 'View', macos: 'NgNativeButton' },\n undefined,\n { textContent: 'title' },\n);\n\n/**\n * A platform button, its label the text inside it:\n *\n * <native-button kind=\"default\" (press)=\"save()\">Save</native-button>\n *\n * On macOS it is an NSButton, on Linux a GtkButton and on iOS a UIButton, drawn by the host, which sends\n * `topButtonPress` when it is clicked, tapped, or pressed by Space, and on macOS by Return (a\n * `default` button) or Escape (a `cancel` one). On Android it is a view pressed through the responder, as a\n * `<pressable>` is, and takes `android_ripple` as one does. The web host draws an HTML `button`.\n * It is a button to assistive technology everywhere, and takes focus.\n */\n@Component({\n selector: 'native-button',\n imports: [Image],\n template: `\n @if (androidPicture(); as source) {\n <image [source]=\"source\" [tintColor]=\"tint()\" style=\"width: 18px; height: 18px\" />\n }\n <ng-content />\n `,\n providers: [{ provide: TouchableBase, useExisting: forwardRef(() => NativeButton) }],\n host: {\n '[kind]': 'kind()',\n '[controlSize]': 'controlSize()',\n '[sfSymbol]': 'symbol()',\n '[drawable]': 'android ? undefined : drawableResource()',\n '[svgIcon]': 'svgIcon()',\n '[iconImage]': 'iosPicture()?.uri',\n '[style.flexDirection]': 'androidPicture() ? \"row\" : undefined',\n '[style.alignItems]': 'androidPicture() ? \"center\" : undefined',\n '[style.gap]': 'androidPicture() ? \"8px\" : undefined',\n '[enabled]': '!pressDisabled()',\n },\n})\nexport class NativeButton extends ControlBase {\n /**\n * What the button does in its window. In a desktop window `default` takes Return and `cancel`\n * takes Escape; elsewhere the kind is a style alone. Unset, it is a plain push button.\n */\n readonly kind = input<ButtonKind>();\n /** AppKit's control size on macOS, and UIKit's button size on iOS. Ignored elsewhere. */\n readonly controlSize = input<ControlSize>();\n /** An SF Symbol beside the label, on iOS and macOS. */\n readonly sfSymbol = input<string>();\n /** Android: a drawable resource beside the label. */\n readonly drawableName = input<string>(undefined, { alias: 'drawable' });\n /** The picture for each OS at once, as on `<native-tab>`. */\n readonly icon = input<ButtonIcon>();\n\n protected readonly symbol = computed(() => {\n const icon = this.icon();\n return this.sfSymbol() ?? (icon && 'sfSymbol' in icon ? icon.sfSymbol : undefined);\n });\n\n protected readonly drawableResource = computed(() => {\n const icon = this.icon();\n return this.drawableName() ?? (icon && 'drawable' in icon ? icon.drawable : undefined);\n });\n\n private readonly svgRenderer = inject(SVG_ICON_RENDERER);\n private readonly svgHost = inject(ViewContainerRef);\n private readonly errors = inject(ErrorHandler);\n protected readonly android = nativePlatform() === 'android';\n /** Where the markup is drawn here, by the app's renderer, as an image. */\n private readonly drawsSvg = this.android || nativePlatform() === 'ios';\n\n protected readonly svgIcon = computed(() =>\n svgIconMarkup(this.icon(), 'native-button', !this.drawsSvg, 'macOS, Linux, iOS and Android'),\n );\n\n /** The markup drawn as an image, on iOS and Android, once the renderer has answered. */\n private readonly drawnSvg = this.drawSvg();\n\n /** The image iOS draws before the title, tinted as a symbol is. */\n protected readonly iosPicture = computed(() =>\n this.android ? undefined : (this.drawnSvg() as ImageURISource | undefined),\n );\n\n /** Android: the image before the label, a drawable's or the drawn markup. */\n protected readonly androidPicture = computed((): ImageURISource | undefined => {\n if (!this.android) return undefined;\n const drawable = this.drawableResource();\n if (drawable) return { uri: drawable };\n return this.drawnSvg() as ImageURISource | undefined;\n });\n\n /** The label's colour, which an Android icon is tinted in: black, as text is, where none is set. */\n protected readonly tint = signal<string | undefined>(undefined);\n\n constructor() {\n super();\n // Only a button with an icon follows its colour: a watch is a look at every commit.\n effect((onCleanup) => {\n if (!this.androidPicture()) return;\n const follow = (colour: unknown) => this.tint.set((colour as string | undefined) ?? 'black');\n follow(this.engine.colour(this.node));\n onCleanup(this.engine.watchColour(this.node, follow));\n });\n }\n\n /**\n * The markup drawn once by the app's renderer, where the platform draws no SVG itself. An answer\n * for an icon the button no longer has is dropped.\n */\n private drawSvg() {\n const drawn = signal<unknown>(undefined);\n if (!this.drawsSvg) return drawn;\n effect((onCleanup) => {\n const markup = this.svgIcon();\n drawn.set(undefined);\n if (!markup) return;\n if (!this.svgRenderer) return warnNoRenderer();\n let current = true;\n onCleanup(() => (current = false));\n const size = this.android ? ANDROID_ICON_SIZE : IOS_SVG_SIZE;\n this.svgRenderer.render(markup, size, this.svgHost).then(\n (source) => current && drawn.set(source ?? undefined),\n (error: unknown) => this.errors.handleError(error),\n );\n });\n return drawn;\n }\n\n /**\n * Where the host draws the button (AppKit, UIKit, GTK), it presses it: the responder would press\n * it twice.\n */\n private readonly drawnByHost = isApplePlatform() || nativePlatform() === 'linux';\n private stopPress: (() => void) | null = null;\n\n protected override roleByDefault(): 'button' {\n return 'button';\n }\n\n protected override accessibleByDefault(): boolean {\n return true;\n }\n\n protected override focusableByDefault(): boolean {\n return true;\n }\n\n protected override disabledForAccessibility(): boolean | undefined {\n return this.disabled();\n }\n\n protected override claims(): boolean {\n return !this.drawnByHost && super.claims();\n }\n\n override ngOnInit(): void {\n super.ngOnInit();\n if (!this.drawnByHost || this.stopPress) return;\n this.stopPress = this.engine.setEventListener(\n this.node as HostNode,\n 'topButtonPress',\n (event) => {\n if (this.pressDisabled()) return;\n this.emitReported(this.press, 'click', event as never, 'click');\n },\n );\n }\n\n override ngOnDestroy(): void {\n super.ngOnDestroy();\n this.stopPress?.();\n }\n}\n\n/** Says once, in development, that a button's SVG icon has nothing to draw it, so it shows none. */\nfunction warnNoRenderer(): void {\n const os = nativePlatform();\n if ((typeof ngDevMode !== 'undefined' && !ngDevMode) || warnedNoRenderer.has(os)) return;\n warnedNoRenderer.add(os);\n console.warn(\n `[angular-native] <native-button> has an SVG icon and nothing to draw it on ${os}, so it ` +\n `shows none. Add withSvgIcons(SvgImages) to provideNativeRouter (withSvgIcons from ` +\n `@ng-native/router, SvgImages from @ng-native/icons), or provide SVG_ICON_RENDERER.`,\n );\n}\n"]}
@@ -75,10 +75,10 @@ export class NativeGestureBase {
75
75
  timestamp: Date.now(),
76
76
  });
77
77
  }
78
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeGestureBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
79
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: NativeGestureBase, isStandalone: true, selector: "[gesture]", inputs: { gesture: { classPropertyName: "gesture", publicName: "gesture", isSignal: true, isRequired: true, transformFunction: null }, trackGesture: { classPropertyName: "trackGesture", publicName: "trackGesture", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "collapsable": "false" } }, ngImport: i0 });
78
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeGestureBase, deps: [], target: i0.ɵɵFactoryTarget.Directive });
79
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.0", type: NativeGestureBase, isStandalone: true, selector: "[gesture]", inputs: { gesture: { classPropertyName: "gesture", publicName: "gesture", isSignal: true, isRequired: true, transformFunction: null }, trackGesture: { classPropertyName: "trackGesture", publicName: "trackGesture", isSignal: true, isRequired: false, transformFunction: null } }, host: { properties: { "collapsable": "false" } }, ngImport: i0 });
80
80
  }
81
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeGestureBase, decorators: [{
81
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeGestureBase, decorators: [{
82
82
  type: Directive,
83
83
  args: [{ selector: '[gesture]', host: { '[collapsable]': 'false' } }]
84
84
  }], ctorParameters: () => [], propDecorators: { gesture: [{ type: i0.Input, args: [{ isSignal: true, alias: "gesture", required: true }] }], trackGesture: [{ type: i0.Input, args: [{ isSignal: true, alias: "trackGesture", required: false }] }] } });
@@ -3,10 +3,10 @@ import * as i0 from "@angular/core";
3
3
  /** Escape hatch for reading a primitive's retained node, e.g. to issue a native command. */
4
4
  export class NativeRef {
5
5
  node = inject(ElementRef).nativeElement;
6
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeRef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
7
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.2.0", type: NativeRef, isStandalone: true, selector: "[nativeRef]", exportAs: ["nativeRef"], ngImport: i0 });
6
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeRef, deps: [], target: i0.ɵɵFactoryTarget.Directive });
7
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "14.0.0", version: "22.3.0", type: NativeRef, isStandalone: true, selector: "[nativeRef]", exportAs: ["nativeRef"], ngImport: i0 });
8
8
  }
9
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: NativeRef, decorators: [{
9
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: NativeRef, decorators: [{
10
10
  type: Directive,
11
11
  args: [{ selector: '[nativeRef]', exportAs: 'nativeRef' }]
12
12
  }] });
@@ -2,7 +2,10 @@ import { InjectionToken, type TemplateRef } from '@angular/core';
2
2
  import * as i0 from "@angular/core";
3
3
  /** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */
4
4
  export declare const PRESS_MENU: InjectionToken<{
5
- open(): boolean;
5
+ /** Whether a press opened the menu, or the host's own touch did, so `(press)` does not fire. */
6
+ takePress(): boolean;
7
+ /** Tell it when the pressable refuses presses, so the host draws no menu then. */
8
+ disableWhile(disabled: () => boolean): void;
6
9
  }>;
7
10
  /**
8
11
  * A menu a press opens: `<pressable [menu]="menu">`, with `<ng-template #menu>` holding
@@ -11,29 +14,56 @@ export declare const PRESS_MENU: InjectionToken<{
11
14
  * select is a menu of `[checked]` items. `open()` opens it from code: `#sort="pressMenu"` names it in
12
15
  * the template.
13
16
  *
14
- * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android
15
- * as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts
16
- * (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in
17
- * development.
17
+ * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, Android as a
18
+ * PopupMenu below it, and iOS as a UIMenu from a clear button laid over the element, which opens it
19
+ * as a touch goes down, as SwiftUI's `Menu` does. From iOS 17.4 a press on the element opens it as
20
+ * `open()` does, for a tap made before the button is laid; the host ignores the request while the
21
+ * menu is showing, as it is after the button's own touch. Before 17.4 iOS had no way to open one
22
+ * from code, so `open()` there opens none. Android and iOS take the
23
+ * `NgNativeMenus` module that Expo Go lacks. Other hosts (Expo Go, the web) draw none yet:
24
+ * there a press fires `(press)`, with one warning in development.
18
25
  *
19
26
  * The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as
20
- * `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,
21
- * as a context menu's.
27
+ * `serializeMenu` makes it, and the item chosen sent as the view's `topContextMenuSelect`, as a
28
+ * context menu's. On iOS, `Menus.setPressMenu(nativeID, entries)` instead, as the menu changes, and
29
+ * null while the pressable is disabled, with `Menus.openPressMenu(nativeID)` to open it from iOS
30
+ * 17.4; the choice comes back by the view's `nativeID`.
22
31
  */
23
32
  export declare class PressMenu {
24
33
  readonly menu: import("@angular/core").InputSignal<TemplateRef<unknown> | null | undefined>;
25
34
  private readonly node;
26
35
  private readonly engine;
27
36
  private readonly menus;
37
+ private readonly os;
28
38
  private readonly built;
39
+ /** iOS's host, which takes the menu by `nativeID` and opens it on a touch itself. */
40
+ private readonly byNativeId;
41
+ private readonly disabled;
42
+ /** The menu as iOS's host has it: none while the pressable is disabled. */
43
+ private readonly shown;
44
+ /** The `nativeID` the menu was last sent to iOS's host under. */
45
+ private sentAs;
29
46
  constructor();
47
+ disableWhile(disabled: () => boolean): void;
48
+ /**
49
+ * Whether a press is the menu's: before iOS 17.4 the host's own touch opened it, wherever it has
50
+ * the menu; elsewhere `open()` opens it now. On iOS React Native's press follows the button's own
51
+ * touch, and a screen reader's, and the host ignores that request while the menu is showing.
52
+ */
53
+ takePress(): boolean;
30
54
  /**
31
55
  * Ask the host to open the menu under the element now. True once the request is sent, which
32
56
  * does not mean the menu showed: the host draws none for a view it is not showing (no window on
33
57
  * macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu
34
- * shows no item, the element has no view yet, or the host draws no press menu.
58
+ * shows no item, the element has no view yet, or the host draws no press menu, or opens it only
59
+ * on a touch (iOS before 17.4).
35
60
  */
36
61
  open(): boolean;
62
+ /**
63
+ * Keep the host's menu on the view as the menu and the pressable's disabled state change, by
64
+ * its `nativeID`, and take it away as the element goes.
65
+ */
66
+ private sendByNativeId;
37
67
  static ɵfac: i0.ɵɵFactoryDeclaration<PressMenu, never>;
38
68
  static ɵdir: i0.ɵɵDirectiveDeclaration<PressMenu, "pressable[menu]", ["pressMenu"], { "menu": { "alias": "menu"; "required": false; "isSignal": true; }; }, {}, never, never, true, never>;
39
69
  }
@@ -1,12 +1,23 @@
1
- import { DestroyRef, Directive, ElementRef, InjectionToken, Injector, forwardRef, inject, input, untracked, } from '@angular/core';
1
+ import { DestroyRef, Directive, ElementRef, InjectionToken, Injector, computed, effect, forwardRef, inject, input, signal, untracked, } from '@angular/core';
2
2
  import { Menus, OS } from '@ng-native/device';
3
3
  import { HostEngine } from '@ng-native/fabric';
4
4
  import { templateMenu } from "./context-menu.js";
5
+ import { byNativeId } from "./native-id.js";
5
6
  import * as i0 from "@angular/core";
6
7
  /** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */
7
8
  export const PRESS_MENU = new InjectionToken('angular-native.pressMenu');
8
- /** Whether the warning for a host that draws no press menu has been given, which it is once. */
9
- let warned = false;
9
+ const drawsNone = '[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux, Android and ' +
10
+ 'iOS do), so the press fires (press) instead.';
11
+ const opensNoneOnIos = "PressMenu.open(): before iOS 17.4 a press menu opens only on a touch or a screen reader's " +
12
+ 'press, and there is no way to open one from code, so this opens none.';
13
+ /** The warnings given in development, each once. */
14
+ const warned = new Set();
15
+ function warnOnce(message) {
16
+ if (typeof ngDevMode === 'undefined' || !ngDevMode || warned.has(message))
17
+ return;
18
+ warned.add(message);
19
+ console.warn(message);
20
+ }
10
21
  /**
11
22
  * A menu a press opens: `<pressable [menu]="menu">`, with `<ng-template #menu>` holding
12
23
  * `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,
@@ -14,14 +25,20 @@ let warned = false;
14
25
  * select is a menu of `[checked]` items. `open()` opens it from code: `#sort="pressMenu"` names it in
15
26
  * the template.
16
27
  *
17
- * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android
18
- * as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts
19
- * (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in
20
- * development.
28
+ * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, Android as a
29
+ * PopupMenu below it, and iOS as a UIMenu from a clear button laid over the element, which opens it
30
+ * as a touch goes down, as SwiftUI's `Menu` does. From iOS 17.4 a press on the element opens it as
31
+ * `open()` does, for a tap made before the button is laid; the host ignores the request while the
32
+ * menu is showing, as it is after the button's own touch. Before 17.4 iOS had no way to open one
33
+ * from code, so `open()` there opens none. Android and iOS take the
34
+ * `NgNativeMenus` module that Expo Go lacks. Other hosts (Expo Go, the web) draw none yet:
35
+ * there a press fires `(press)`, with one warning in development.
21
36
  *
22
37
  * The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as
23
- * `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,
24
- * as a context menu's.
38
+ * `serializeMenu` makes it, and the item chosen sent as the view's `topContextMenuSelect`, as a
39
+ * context menu's. On iOS, `Menus.setPressMenu(nativeID, entries)` instead, as the menu changes, and
40
+ * null while the pressable is disabled, with `Menus.openPressMenu(nativeID)` to open it from iOS
41
+ * 17.4; the choice comes back by the view's `nativeID`.
25
42
  */
26
43
  export class PressMenu {
27
44
  menu = input(/* @ts-ignore */
@@ -29,7 +46,17 @@ export class PressMenu {
29
46
  node = inject(ElementRef).nativeElement;
30
47
  engine = inject(HostEngine);
31
48
  menus = inject(Menus);
32
- built = templateMenu(() => this.menu() ?? null, inject(Injector), inject(OS));
49
+ os = inject(OS);
50
+ built = templateMenu(() => this.menu() ?? null, inject(Injector), this.os);
51
+ /** iOS's host, which takes the menu by `nativeID` and opens it on a touch itself. */
52
+ byNativeId = this.os === 'ios' && this.menus.pressMenuByNativeId;
53
+ disabled = signal(() => false, /* @ts-ignore */
54
+ ...(ngDevMode ? [{ debugName: "disabled" }] : /* istanbul ignore next */ []));
55
+ /** The menu as iOS's host has it: none while the pressable is disabled. */
56
+ shown = computed(() => (this.disabled()() ? null : this.built.sent()), /* @ts-ignore */
57
+ ...(ngDevMode ? [{ debugName: "shown" }] : /* istanbul ignore next */ []));
58
+ /** The `nativeID` the menu was last sent to iOS's host under. */
59
+ sentAs = null;
33
60
  constructor() {
34
61
  const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {
35
62
  const id = event.nativeEvent?.id;
@@ -37,23 +64,42 @@ export class PressMenu {
37
64
  this.built.choose(id);
38
65
  });
39
66
  inject(DestroyRef).onDestroy(stop);
67
+ if (this.byNativeId)
68
+ this.sendByNativeId();
69
+ }
70
+ disableWhile(disabled) {
71
+ this.disabled.set(disabled);
72
+ }
73
+ /**
74
+ * Whether a press is the menu's: before iOS 17.4 the host's own touch opened it, wherever it has
75
+ * the menu; elsewhere `open()` opens it now. On iOS React Native's press follows the button's own
76
+ * touch, and a screen reader's, and the host ignores that request while the menu is showing.
77
+ */
78
+ takePress() {
79
+ return this.byNativeId && !this.menus.opensPressMenus
80
+ ? untracked(this.built.sent) !== null
81
+ : this.open();
40
82
  }
41
83
  /**
42
84
  * Ask the host to open the menu under the element now. True once the request is sent, which
43
85
  * does not mean the menu showed: the host draws none for a view it is not showing (no window on
44
86
  * macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu
45
- * shows no item, the element has no view yet, or the host draws no press menu.
87
+ * shows no item, the element has no view yet, or the host draws no press menu, or opens it only
88
+ * on a touch (iOS before 17.4).
46
89
  */
47
90
  open() {
91
+ if (this.byNativeId && this.menus.opensPressMenus) {
92
+ const nativeID = this.sentAs;
93
+ if (nativeID === null || untracked(this.shown) === null)
94
+ return false;
95
+ this.menus.openPressMenu(nativeID);
96
+ return true;
97
+ }
48
98
  const entries = untracked(this.built.sent);
49
99
  if (!entries)
50
100
  return false;
51
101
  if (!this.menus.popsUpMenus) {
52
- if (typeof ngDevMode !== 'undefined' && ngDevMode && !warned) {
53
- warned = true;
54
- console.warn('[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux and ' +
55
- 'Android do), so the press fires (press) instead.');
56
- }
102
+ warnOnce(this.byNativeId ? opensNoneOnIos : drawsNone);
57
103
  return false;
58
104
  }
59
105
  const view = this.engine.tagOf?.(this.node) ?? null;
@@ -62,10 +108,25 @@ export class PressMenu {
62
108
  this.menus.popUpMenu(view, entries);
63
109
  return true;
64
110
  }
65
- static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive });
66
- static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.2.0", type: PressMenu, isStandalone: true, selector: "pressable[menu]", inputs: { menu: { classPropertyName: "menu", publicName: "menu", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }], exportAs: ["pressMenu"], ngImport: i0 });
111
+ /**
112
+ * Keep the host's menu on the view as the menu and the pressable's disabled state change, by
113
+ * its `nativeID`, and take it away as the element goes.
114
+ */
115
+ sendByNativeId() {
116
+ const choose = (id) => this.built.choose(id);
117
+ const send = byNativeId(this.engine, this.node, (nativeID) => {
118
+ this.sentAs = nativeID;
119
+ this.menus.setPressMenu(nativeID, untracked(this.shown), choose);
120
+ }, (nativeID) => this.menus.setPressMenu(nativeID, null, choose));
121
+ effect(() => {
122
+ this.shown();
123
+ send();
124
+ });
125
+ }
126
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: PressMenu, deps: [], target: i0.ɵɵFactoryTarget.Directive });
127
+ static ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "17.1.0", version: "22.3.0", type: PressMenu, isStandalone: true, selector: "pressable[menu]", inputs: { menu: { classPropertyName: "menu", publicName: "menu", isSignal: true, isRequired: false, transformFunction: null } }, providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }], exportAs: ["pressMenu"], ngImport: i0 });
67
128
  }
68
- i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.2.0", ngImport: i0, type: PressMenu, decorators: [{
129
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "22.3.0", ngImport: i0, type: PressMenu, decorators: [{
69
130
  type: Directive,
70
131
  args: [{
71
132
  selector: 'pressable[menu]',
@@ -1 +1 @@
1
- {"version":3,"file":"press-menu.js","sourceRoot":"","sources":["../src/press-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,UAAU,EACV,MAAM,EACN,KAAK,EACL,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;;AAEjD,wFAAwF;AACxF,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,CAAsB,0BAA0B,CAAC,CAAC;AAI9F,gGAAgG;AAChG,IAAI,MAAM,GAAG,KAAK,CAAC;AAEnB;;;;;;;;;;;;;;;GAeG;AAMH,MAAM,OAAO,SAAS;IACX,IAAI,GAAG,KAAK;wFAA+B,CAAC;IAEpC,IAAI,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,aAAyB,CAAC;IACpD,MAAM,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5B,KAAK,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IACtB,KAAK,GAAG,YAAY,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,IAAI,IAAI,EAAE,MAAM,CAAC,QAAQ,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC;IAE/F;QACE,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,sBAAsB,EAAE,CAAC,KAAK,EAAE,EAAE;YACrF,MAAM,EAAE,GAAI,KAA2C,CAAC,WAAW,EAAE,EAAE,CAAC;YACxE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CAAC;iBAC/E","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n InjectionToken,\n Injector,\n forwardRef,\n inject,\n input,\n untracked,\n type TemplateRef,\n} from '@angular/core';\nimport { Menus, OS } from '@ng-native/device';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\nimport { templateMenu } from './context-menu.ts';\n\n/** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */\nexport const PRESS_MENU = new InjectionToken<{ open(): boolean }>('angular-native.pressMenu');\n\ndeclare const ngDevMode: unknown;\n\n/** Whether the warning for a host that draws no press menu has been given, which it is once. */\nlet warned = false;\n\n/**\n * A menu a press opens: `<pressable [menu]=\"menu\">`, with `<ng-template #menu>` holding\n * `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,\n * Space on the focused element opens it under the element, and `(press)` does not fire. A pop-up\n * select is a menu of `[checked]` items. `open()` opens it from code: `#sort=\"pressMenu\"` names it in\n * the template.\n *\n * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, and Android\n * as a PopupMenu below it, which takes the `NgNativeMenus` module that Expo Go lacks. Other hosts\n * (iOS, Expo Go, the web) draw none yet: there a press fires `(press)`, with one warning in\n * development.\n *\n * The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as\n * `serializeMenu` makes it. The host sends the item chosen as the view's `topContextMenuSelect`,\n * as a context menu's.\n */\n@Directive({\n selector: 'pressable[menu]',\n exportAs: 'pressMenu',\n providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }],\n})\nexport class PressMenu {\n readonly menu = input<TemplateRef<unknown> | null>();\n\n private readonly node = inject(ElementRef).nativeElement as HostNode;\n private readonly engine = inject(HostEngine);\n private readonly menus = inject(Menus);\n private readonly built = templateMenu(() => this.menu() ?? null, inject(Injector), inject(OS));\n\n constructor() {\n const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {\n const id = (event as { nativeEvent?: { id?: string } }).nativeEvent?.id;\n if (id !== undefined) this.built.choose(id);\n });\n inject(DestroyRef).onDestroy(stop);\n }\n\n /**\n * Ask the host to open the menu under the element now. True once the request is sent, which\n * does not mean the menu showed: the host draws none for a view it is not showing (no window on\n * macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu\n * shows no item, the element has no view yet, or the host draws no press menu.\n */\n open(): boolean {\n const entries = untracked(this.built.sent);\n if (!entries) return false;\n if (!this.menus.popsUpMenus) {\n if (typeof ngDevMode !== 'undefined' && ngDevMode && !warned) {\n warned = true;\n console.warn(\n '[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux and ' +\n 'Android do), so the press fires (press) instead.',\n );\n }\n return false;\n }\n const view = this.engine.tagOf?.(this.node) ?? null;\n if (view === null) return false;\n this.menus.popUpMenu(view, entries);\n return true;\n }\n}\n"]}
1
+ {"version":3,"file":"press-menu.js","sourceRoot":"","sources":["../src/press-menu.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,QAAQ,EACR,MAAM,EACN,UAAU,EACV,MAAM,EACN,KAAK,EACL,MAAM,EACN,SAAS,GAEV,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,KAAK,EAAE,EAAE,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAiB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;;AAE5C,wFAAwF;AACxF,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,cAAc,CAKzC,0BAA0B,CAAC,CAAC;AAI/B,MAAM,SAAS,GACb,6FAA6F;IAC7F,8CAA8C,CAAC;AACjD,MAAM,cAAc,GAClB,4FAA4F;IAC5F,uEAAuE,CAAC;AAE1E,oDAAoD;AACpD,MAAM,MAAM,GAAG,IAAI,GAAG,EAAU,CAAC;AAEjC,S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Q,EAAE,iBAAiB;oBAC3B,QAAQ,EAAE,WAAW;oBACrB,SAAS,EAAE,CAAC,EAAE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,UAAU,CAAC,GAAG,EAAE,UAAU,CAAC,EAAE,CAAC;iBAC/E","sourcesContent":["import {\n DestroyRef,\n Directive,\n ElementRef,\n InjectionToken,\n Injector,\n computed,\n effect,\n forwardRef,\n inject,\n input,\n signal,\n untracked,\n type TemplateRef,\n} from '@angular/core';\nimport { Menus, OS } from '@ng-native/device';\nimport { HostEngine, type HostNode } from '@ng-native/fabric';\nimport { templateMenu } from './context-menu.ts';\nimport { byNativeId } from './native-id.ts';\n\n/** The `[menu]` on a `<pressable>`, which a press opens instead of firing `(press)`. */\nexport const PRESS_MENU = new InjectionToken<{\n /** Whether a press opened the menu, or the host's own touch did, so `(press)` does not fire. */\n takePress(): boolean;\n /** Tell it when the pressable refuses presses, so the host draws no menu then. */\n disableWhile(disabled: () => boolean): void;\n}>('angular-native.pressMenu');\n\ndeclare const ngDevMode: unknown;\n\nconst drawsNone =\n '[menu] on a <pressable>: this host draws no menu on a press yet (macOS, Linux, Android and ' +\n 'iOS do), so the press fires (press) instead.';\nconst opensNoneOnIos =\n \"PressMenu.open(): before iOS 17.4 a press menu opens only on a touch or a screen reader's \" +\n 'press, and there is no way to open one from code, so this opens none.';\n\n/** The warnings given in development, each once. */\nconst warned = new Set<string>();\n\nfunction warnOnce(message: string): void {\n if (typeof ngDevMode === 'undefined' || !ngDevMode || warned.has(message)) return;\n warned.add(message);\n console.warn(message);\n}\n\n/**\n * A menu a press opens: `<pressable [menu]=\"menu\">`, with `<ng-template #menu>` holding\n * `<menu-item>`s, as a `[contextMenu]` is written. A click, a screen reader's press or, on macOS,\n * Space on the focused element opens it under the element, and `(press)` does not fire. A pop-up\n * select is a menu of `[checked]` items. `open()` opens it from code: `#sort=\"pressMenu\"` names it in\n * the template.\n *\n * macOS draws it as an `NSMenu` under the element, Linux as a popover menu below it, Android as a\n * PopupMenu below it, and iOS as a UIMenu from a clear button laid over the element, which opens it\n * as a touch goes down, as SwiftUI's `Menu` does. From iOS 17.4 a press on the element opens it as\n * `open()` does, for a tap made before the button is laid; the host ignores the request while the\n * menu is showing, as it is after the button's own touch. Before 17.4 iOS had no way to open one\n * from code, so `open()` there opens none. Android and iOS take the\n * `NgNativeMenus` module that Expo Go lacks. Other hosts (Expo Go, the web) draw none yet:\n * there a press fires `(press)`, with one warning in development.\n *\n * The host contract: `Menus.popUpMenu(view, entries)` with the view's tag and the menu as\n * `serializeMenu` makes it, and the item chosen sent as the view's `topContextMenuSelect`, as a\n * context menu's. On iOS, `Menus.setPressMenu(nativeID, entries)` instead, as the menu changes, and\n * null while the pressable is disabled, with `Menus.openPressMenu(nativeID)` to open it from iOS\n * 17.4; the choice comes back by the view's `nativeID`.\n */\n@Directive({\n selector: 'pressable[menu]',\n exportAs: 'pressMenu',\n providers: [{ provide: PRESS_MENU, useExisting: forwardRef(() => PressMenu) }],\n})\nexport class PressMenu {\n readonly menu = input<TemplateRef<unknown> | null>();\n\n private readonly node = inject(ElementRef).nativeElement as HostNode;\n private readonly engine = inject(HostEngine);\n private readonly menus = inject(Menus);\n private readonly os = inject(OS);\n private readonly built = templateMenu(() => this.menu() ?? null, inject(Injector), this.os);\n /** iOS's host, which takes the menu by `nativeID` and opens it on a touch itself. */\n private readonly byNativeId = this.os === 'ios' && this.menus.pressMenuByNativeId;\n private readonly disabled = signal<() => boolean>(() => false);\n /** The menu as iOS's host has it: none while the pressable is disabled. */\n private readonly shown = computed(() => (this.disabled()() ? null : this.built.sent()));\n /** The `nativeID` the menu was last sent to iOS's host under. */\n private sentAs: string | null = null;\n\n constructor() {\n const stop = this.engine.setEventListener(this.node, 'topContextMenuSelect', (event) => {\n const id = (event as { nativeEvent?: { id?: string } }).nativeEvent?.id;\n if (id !== undefined) this.built.choose(id);\n });\n inject(DestroyRef).onDestroy(stop);\n if (this.byNativeId) this.sendByNativeId();\n }\n\n disableWhile(disabled: () => boolean): void {\n this.disabled.set(disabled);\n }\n\n /**\n * Whether a press is the menu's: before iOS 17.4 the host's own touch opened it, wherever it has\n * the menu; elsewhere `open()` opens it now. On iOS React Native's press follows the button's own\n * touch, and a screen reader's, and the host ignores that request while the menu is showing.\n */\n takePress(): boolean {\n return this.byNativeId && !this.menus.opensPressMenus\n ? untracked(this.built.sent) !== null\n : this.open();\n }\n\n /**\n * Ask the host to open the menu under the element now. True once the request is sent, which\n * does not mean the menu showed: the host draws none for a view it is not showing (no window on\n * macOS, not mapped on Linux), and does not report that. False when no request is sent: the menu\n * shows no item, the element has no view yet, or the host draws no press menu, or opens it only\n * on a touch (iOS before 17.4).\n */\n open(): boolean {\n if (this.byNativeId && this.menus.opensPressMenus) {\n const nativeID = this.sentAs;\n if (nativeID === null || untracked(this.shown) === null) return false;\n this.menus.openPressMenu(nativeID);\n return true;\n }\n const entries = untracked(this.built.sent);\n if (!entries) return false;\n if (!this.menus.popsUpMenus) {\n warnOnce(this.byNativeId ? opensNoneOnIos : drawsNone);\n return false;\n }\n const view = this.engine.tagOf?.(this.node) ?? null;\n if (view === null) return false;\n this.menus.popUpMenu(view, entries);\n return true;\n }\n\n /**\n * Keep the host's menu on the view as the menu and the pressable's disabled state change, by\n * its `nativeID`, and take it away as the element goes.\n */\n private sendByNativeId(): void {\n const choose = (id: string) => this.built.choose(id);\n const send = byNativeId(\n this.engine,\n this.node,\n (nativeID) => {\n this.sentAs = nativeID;\n this.menus.setPressMenu(nativeID, untracked(this.shown), choose);\n },\n (nativeID) => this.menus.setPressMenu(nativeID, null, choose),\n );\n effect(() => {\n this.shown();\n send();\n });\n }\n}\n"]}