react-native-unified-action-sheet 0.1.0 → 0.2.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 (52) hide show
  1. package/CHANGELOG.md +41 -1
  2. package/README.md +42 -21
  3. package/android/src/main/java/com/unifiedactionsheet/PromptOptions.kt +132 -0
  4. package/android/src/main/java/com/unifiedactionsheet/SheetContentBuilder.kt +31 -0
  5. package/android/src/main/java/com/unifiedactionsheet/SheetPresenters.kt +54 -0
  6. package/android/src/main/java/com/unifiedactionsheet/UnifiedActionSheetModule.kt +55 -0
  7. package/ios/UnifiedActionSheet.mm +47 -0
  8. package/ios/UnifiedActionSheetImpl.swift +101 -4
  9. package/jest/index.d.ts +15 -1
  10. package/jest/index.js +28 -0
  11. package/lib/commonjs/NativeUnifiedActionSheet.js.map +1 -1
  12. package/lib/commonjs/action-sheet-options.interface.js +4 -0
  13. package/lib/commonjs/common-options.interface.js +2 -0
  14. package/lib/commonjs/common-options.interface.js.map +1 -0
  15. package/lib/commonjs/index.js +39 -4
  16. package/lib/commonjs/index.js.map +1 -1
  17. package/lib/commonjs/prompt-options.interface.js +6 -0
  18. package/lib/commonjs/prompt-options.interface.js.map +1 -0
  19. package/lib/module/NativeUnifiedActionSheet.js.map +1 -1
  20. package/lib/module/action-sheet-options.interface.js +2 -0
  21. package/lib/module/common-options.interface.js +2 -0
  22. package/lib/module/common-options.interface.js.map +1 -0
  23. package/lib/module/index.js +37 -3
  24. package/lib/module/index.js.map +1 -1
  25. package/lib/module/prompt-options.interface.js +4 -0
  26. package/lib/module/prompt-options.interface.js.map +1 -0
  27. package/lib/typescript/commonjs/src/NativeUnifiedActionSheet.d.ts +20 -0
  28. package/lib/typescript/commonjs/src/NativeUnifiedActionSheet.d.ts.map +1 -1
  29. package/lib/typescript/commonjs/src/action-sheet-options.interface.d.ts +4 -13
  30. package/lib/typescript/commonjs/src/action-sheet-options.interface.d.ts.map +1 -1
  31. package/lib/typescript/commonjs/src/common-options.interface.d.ts +17 -0
  32. package/lib/typescript/commonjs/src/common-options.interface.d.ts.map +1 -0
  33. package/lib/typescript/commonjs/src/index.d.ts +4 -0
  34. package/lib/typescript/commonjs/src/index.d.ts.map +1 -1
  35. package/lib/typescript/commonjs/src/prompt-options.interface.d.ts +19 -0
  36. package/lib/typescript/commonjs/src/prompt-options.interface.d.ts.map +1 -0
  37. package/lib/typescript/module/src/NativeUnifiedActionSheet.d.ts +20 -0
  38. package/lib/typescript/module/src/NativeUnifiedActionSheet.d.ts.map +1 -1
  39. package/lib/typescript/module/src/action-sheet-options.interface.d.ts +4 -13
  40. package/lib/typescript/module/src/action-sheet-options.interface.d.ts.map +1 -1
  41. package/lib/typescript/module/src/common-options.interface.d.ts +17 -0
  42. package/lib/typescript/module/src/common-options.interface.d.ts.map +1 -0
  43. package/lib/typescript/module/src/index.d.ts +4 -0
  44. package/lib/typescript/module/src/index.d.ts.map +1 -1
  45. package/lib/typescript/module/src/prompt-options.interface.d.ts +19 -0
  46. package/lib/typescript/module/src/prompt-options.interface.d.ts.map +1 -0
  47. package/package.json +1 -1
  48. package/src/NativeUnifiedActionSheet.ts +17 -0
  49. package/src/action-sheet-options.interface.ts +9 -19
  50. package/src/common-options.interface.ts +18 -0
  51. package/src/index.tsx +65 -3
  52. package/src/prompt-options.interface.ts +27 -0
@@ -1 +1 @@
1
- {"version":3,"file":"NativeUnifiedActionSheet.d.ts","sourceRoot":"","sources":["../../../../src/NativeUnifiedActionSheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,0BAA0B,CAAC,OAAO,EAAE;QAClC,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;QACpC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;QACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,CAAC,EAAE;YACX,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,KAAK,EAAE,MAAM,CAAC;YACd,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,kBAAkB,IAAI,IAAI,CAAC;IAC3B,sBAAsB,IAAI,IAAI,CAAC;CAChC;;AAED,wBAA4E"}
1
+ {"version":3,"file":"NativeUnifiedActionSheet.d.ts","sourceRoot":"","sources":["../../../../src/NativeUnifiedActionSheet.ts"],"names":[],"mappings":"AAAA,OAAO,EAAuB,KAAK,WAAW,EAAE,MAAM,cAAc,CAAC;AAErE,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,0BAA0B,CAAC,OAAO,EAAE;QAClC,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;QACpC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;QACjC,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,eAAe,CAAC,EAAE,MAAM,CAAC;QACzB,UAAU,CAAC,EAAE;YACX,CAAC,EAAE,MAAM,CAAC;YACV,CAAC,EAAE,MAAM,CAAC;YACV,KAAK,EAAE,MAAM,CAAC;YACd,MAAM,EAAE,MAAM,CAAC;SAChB,CAAC;KACH,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IACpB,qBAAqB,CAAC,OAAO,EAAE;QAC7B,OAAO,EAAE,MAAM,EAAE,CAAC;QAClB,iBAAiB,CAAC,EAAE,MAAM,CAAC;QAC3B,wBAAwB,CAAC,EAAE,MAAM,EAAE,CAAC;QACpC,qBAAqB,CAAC,EAAE,MAAM,EAAE,CAAC;QACjC,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,OAAO,CAAC,EAAE,MAAM,CAAC;QACjB,WAAW,CAAC,EAAE,MAAM,CAAC;QACrB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,YAAY,CAAC,EAAE,MAAM,CAAC;QACtB,eAAe,CAAC,EAAE,OAAO,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;QAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;QAC1B,mBAAmB,CAAC,EAAE,MAAM,CAAC;QAC7B,kBAAkB,CAAC,EAAE,MAAM,CAAC;KAC7B,GAAG,OAAO,CAAC;QAAE,WAAW,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;IACnD,kBAAkB,IAAI,IAAI,CAAC;IAC3B,sBAAsB,IAAI,IAAI,CAAC;CAChC;;AAED,wBAA4E"}
@@ -1,27 +1,18 @@
1
- export interface ActionSheetButtonInterface {
2
- label: string;
3
- style?: 'cancel' | 'destructive';
4
- disabled?: boolean;
1
+ import type { BaseAndroidOptionsInterface, BaseButtonInterface, BaseOptionsInterface } from './common-options.interface.js';
2
+ export interface ActionSheetButtonInterface extends BaseButtonInterface {
5
3
  onPress?: () => void;
6
4
  }
7
5
  export interface ActionSheetAnchorInterface {
8
6
  measureInWindow: (callback: (x: number, y: number, width: number, height: number) => void) => void;
9
7
  }
10
- export interface ActionSheetCommonOptionsInterface {
8
+ export interface ActionSheetCommonOptionsInterface extends BaseOptionsInterface {
11
9
  options: ActionSheetButtonInterface[];
12
- title?: string;
13
- message?: string;
14
- tintColor?: string;
15
- cancelButtonTintColor?: string;
16
- userInterfaceStyle?: 'light' | 'dark';
17
10
  anchor?: ActionSheetAnchorInterface | {
18
11
  current: ActionSheetAnchorInterface | null;
19
12
  } | null;
20
- destructiveColor?: string;
21
13
  presentationStyle?: 'centered' | 'anchored';
22
14
  }
23
- export interface ActionSheetAndroidOptionsInterface {
24
- buttonTextAlignment?: 'start' | 'center';
15
+ export interface ActionSheetAndroidOptionsInterface extends BaseAndroidOptionsInterface {
25
16
  anchorAlignment?: 'start' | 'center';
26
17
  }
27
18
  export interface ActionSheetOptionsInterface extends ActionSheetCommonOptionsInterface, ActionSheetAndroidOptionsInterface {
@@ -1 +1 @@
1
- {"version":3,"file":"action-sheet-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/action-sheet-options.interface.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,0BAA0B;IACzC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;IAGnB,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAID,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,CACf,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,KACpE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,iCAAiC;IAChD,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,kBAAkB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;IACtC,MAAM,CAAC,EACH,0BAA0B,GAC1B;QAAE,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAA;KAAE,GAC9C,IAAI,CAAC;IACT,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,iBAAiB,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC7C;AAED,MAAM,WAAW,kCAAkC;IACjD,mBAAmB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzC,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,2BACf,SACE,iCAAiC,EACjC,kCAAkC;CAAG"}
1
+ {"version":3,"file":"action-sheet-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/action-sheet-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA4B,CAAC;AAEpC,MAAM,WAAW,0BAA2B,SAAQ,mBAAmB;IACrE,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB;AAED,MAAM,WAAW,0BAA0B;IACzC,eAAe,EAAE,CACf,QAAQ,EAAE,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,IAAI,KACpE,IAAI,CAAC;CACX;AAED,MAAM,WAAW,iCAAkC,SAAQ,oBAAoB;IAC7E,OAAO,EAAE,0BAA0B,EAAE,CAAC;IACtC,MAAM,CAAC,EACH,0BAA0B,GAC1B;QAAE,OAAO,EAAE,0BAA0B,GAAG,IAAI,CAAA;KAAE,GAC9C,IAAI,CAAC;IACT,iBAAiB,CAAC,EAAE,UAAU,GAAG,UAAU,CAAC;CAC7C;AAED,MAAM,WAAW,kCAAmC,SAAQ,2BAA2B;IACrF,eAAe,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CACtC;AAED,MAAM,WAAW,2BACf,SACE,iCAAiC,EACjC,kCAAkC;CAAG"}
@@ -0,0 +1,17 @@
1
+ export interface BaseButtonInterface {
2
+ label: string;
3
+ style?: 'cancel' | 'destructive';
4
+ disabled?: boolean;
5
+ }
6
+ export interface BaseOptionsInterface {
7
+ title?: string;
8
+ message?: string;
9
+ tintColor?: string;
10
+ cancelButtonTintColor?: string;
11
+ destructiveColor?: string;
12
+ userInterfaceStyle?: 'light' | 'dark';
13
+ }
14
+ export interface BaseAndroidOptionsInterface {
15
+ buttonTextAlignment?: 'start' | 'center';
16
+ }
17
+ //# sourceMappingURL=common-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"common-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/common-options.interface.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,mBAAmB;IAClC,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,CAAC,EAAE,QAAQ,GAAG,aAAa,CAAC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,oBAAoB;IACnC,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,qBAAqB,CAAC,EAAE,MAAM,CAAC;IAC/B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,kBAAkB,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CACvC;AAED,MAAM,WAAW,2BAA2B;IAC1C,mBAAmB,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC1C"}
@@ -1,6 +1,10 @@
1
1
  import type { ActionSheetOptionsInterface } from './action-sheet-options.interface.js';
2
+ export type { BaseButtonInterface, BaseOptionsInterface, BaseAndroidOptionsInterface, } from './common-options.interface.js';
3
+ export type { PromptButtonInterface, PromptCommonOptionsInterface, PromptAndroidOptionsInterface, PromptOptionsInterface, PromptResultInterface, } from './prompt-options.interface.js';
4
+ import type { PromptOptionsInterface, PromptResultInterface } from './prompt-options.interface.js';
2
5
  export type { ActionSheetAnchorInterface, ActionSheetButtonInterface, ActionSheetCommonOptionsInterface, ActionSheetAndroidOptionsInterface, ActionSheetOptionsInterface, } from './action-sheet-options.interface.js';
3
6
  export declare const showActionSheetWithOptions: (options: ActionSheetOptionsInterface) => Promise<number | undefined>;
4
7
  export declare const dismissActionSheet: () => void;
5
8
  export declare const dismissAllActionSheets: () => void;
9
+ export declare const showPromptWithOptions: (options: PromptOptionsInterface) => Promise<PromptResultInterface | undefined>;
6
10
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAkC,CAAC;AAEpF,YAAY,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,iCAAiC,EACjC,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,qCAAkC,CAAC;AAsF1C,eAAO,MAAM,0BAA0B,GACrC,SAAS,2BAA2B,KACnC,OAAO,CAAC,MAAM,GAAG,SAAS,CAiB5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,IAIrC,CAAC;AAIF,eAAO,MAAM,sBAAsB,QAAO,IAIzC,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/index.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,2BAA2B,EAAE,MAAM,qCAAkC,CAAC;AAEpF,YAAY,EACV,mBAAmB,EACnB,oBAAoB,EACpB,2BAA2B,GAC5B,MAAM,+BAA4B,CAAC;AAEpC,YAAY,EACV,qBAAqB,EACrB,4BAA4B,EAC5B,6BAA6B,EAC7B,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,+BAA4B,CAAC;AAEpC,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACtB,MAAM,+BAA4B,CAAC;AAEpC,YAAY,EACV,0BAA0B,EAC1B,0BAA0B,EAC1B,iCAAiC,EACjC,kCAAkC,EAClC,2BAA2B,GAC5B,MAAM,qCAAkC,CAAC;AAmG1C,eAAO,MAAM,0BAA0B,GACrC,SAAS,2BAA2B,KACnC,OAAO,CAAC,MAAM,GAAG,SAAS,CAiB5B,CAAC;AAEF,eAAO,MAAM,kBAAkB,QAAO,IAIrC,CAAC;AAIF,eAAO,MAAM,sBAAsB,QAAO,IAIzC,CAAC;AAMF,eAAO,MAAM,qBAAqB,GAChC,SAAS,sBAAsB,KAC9B,OAAO,CAAC,qBAAqB,GAAG,SAAS,CAsB3C,CAAC"}
@@ -0,0 +1,19 @@
1
+ import type { BaseAndroidOptionsInterface, BaseButtonInterface, BaseOptionsInterface } from './common-options.interface.js';
2
+ export interface PromptButtonInterface extends BaseButtonInterface {
3
+ onPress?: (text: string) => void;
4
+ }
5
+ export interface PromptCommonOptionsInterface extends BaseOptionsInterface {
6
+ options: PromptButtonInterface[];
7
+ placeholder?: string;
8
+ defaultValue?: string;
9
+ keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'url';
10
+ secureTextEntry?: boolean;
11
+ }
12
+ export type PromptAndroidOptionsInterface = BaseAndroidOptionsInterface;
13
+ export interface PromptOptionsInterface extends PromptCommonOptionsInterface, PromptAndroidOptionsInterface {
14
+ }
15
+ export interface PromptResultInterface {
16
+ buttonIndex: number;
17
+ text: string;
18
+ }
19
+ //# sourceMappingURL=prompt-options.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prompt-options.interface.d.ts","sourceRoot":"","sources":["../../../../src/prompt-options.interface.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,2BAA2B,EAC3B,mBAAmB,EACnB,oBAAoB,EACrB,MAAM,+BAA4B,CAAC;AAEpC,MAAM,WAAW,qBAAsB,SAAQ,mBAAmB;IAChE,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CAClC;AAED,MAAM,WAAW,4BAA6B,SAAQ,oBAAoB;IACxE,OAAO,EAAE,qBAAqB,EAAE,CAAC;IACjC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,YAAY,CAAC,EAAE,SAAS,GAAG,eAAe,GAAG,SAAS,GAAG,WAAW,GAAG,KAAK,CAAC;IAC7E,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B;AAED,MAAM,MAAM,6BAA6B,GAAG,2BAA2B,CAAC;AAExE,MAAM,WAAW,sBACf,SAAQ,4BAA4B,EAAE,6BAA6B;CAAG;AAExE,MAAM,WAAW,qBAAqB;IACpC,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,CAAC;CACd"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-unified-action-sheet",
3
- "version": "0.1.0",
3
+ "version": "0.2.0",
4
4
  "description": "Unified action sheet for React Native: a native UIAlertController on iOS, a native AppCompatDialog on Android",
5
5
  "main": "./lib/commonjs/index.js",
6
6
  "sideEffects": false,
@@ -22,6 +22,23 @@ export interface Spec extends TurboModule {
22
22
  height: number;
23
23
  };
24
24
  }): Promise<number>;
25
+ showPromptWithOptions(options: {
26
+ options: string[];
27
+ cancelButtonIndex?: number;
28
+ destructiveButtonIndices?: number[];
29
+ disabledButtonIndices?: number[];
30
+ title?: string;
31
+ message?: string;
32
+ placeholder?: string;
33
+ defaultValue?: string;
34
+ keyboardType?: string;
35
+ secureTextEntry?: boolean;
36
+ tintColor?: string;
37
+ cancelButtonTintColor?: string;
38
+ destructiveColor?: string;
39
+ buttonTextAlignment?: string;
40
+ userInterfaceStyle?: string;
41
+ }): Promise<{ buttonIndex: number; text: string }>;
25
42
  dismissActionSheet(): void;
26
43
  dismissAllActionSheets(): void;
27
44
  }
@@ -1,39 +1,29 @@
1
- /// One button. `style` mirrors React Native's own Alert API and the native
2
- /// button roles, which are mutually exclusive; `disabled` is independent of it.
3
- export interface ActionSheetButtonInterface {
4
- label: string;
5
- style?: 'cancel' | 'destructive';
6
- disabled?: boolean;
7
- /// Runs when this button resolves the sheet, so callers need not match on the
8
- /// index. A dismissal that resolves the cancel button counts as pressing it.
1
+ import type {
2
+ BaseAndroidOptionsInterface,
3
+ BaseButtonInterface,
4
+ BaseOptionsInterface,
5
+ } from './common-options.interface';
6
+
7
+ export interface ActionSheetButtonInterface extends BaseButtonInterface {
9
8
  onPress?: () => void;
10
9
  }
11
10
 
12
- /// Anything measurable — every React Native host component ref has this method,
13
- /// so a `useRef` on a View, Pressable or Touchable satisfies it.
14
11
  export interface ActionSheetAnchorInterface {
15
12
  measureInWindow: (
16
13
  callback: (x: number, y: number, width: number, height: number) => void
17
14
  ) => void;
18
15
  }
19
16
 
20
- export interface ActionSheetCommonOptionsInterface {
17
+ export interface ActionSheetCommonOptionsInterface extends BaseOptionsInterface {
21
18
  options: ActionSheetButtonInterface[];
22
- title?: string;
23
- message?: string;
24
- tintColor?: string;
25
- cancelButtonTintColor?: string;
26
- userInterfaceStyle?: 'light' | 'dark';
27
19
  anchor?:
28
20
  | ActionSheetAnchorInterface
29
21
  | { current: ActionSheetAnchorInterface | null }
30
22
  | null;
31
- destructiveColor?: string;
32
23
  presentationStyle?: 'centered' | 'anchored';
33
24
  }
34
25
 
35
- export interface ActionSheetAndroidOptionsInterface {
36
- buttonTextAlignment?: 'start' | 'center';
26
+ export interface ActionSheetAndroidOptionsInterface extends BaseAndroidOptionsInterface {
37
27
  anchorAlignment?: 'start' | 'center';
38
28
  }
39
29
 
@@ -0,0 +1,18 @@
1
+ export interface BaseButtonInterface {
2
+ label: string;
3
+ style?: 'cancel' | 'destructive';
4
+ disabled?: boolean;
5
+ }
6
+
7
+ export interface BaseOptionsInterface {
8
+ title?: string;
9
+ message?: string;
10
+ tintColor?: string;
11
+ cancelButtonTintColor?: string;
12
+ destructiveColor?: string;
13
+ userInterfaceStyle?: 'light' | 'dark';
14
+ }
15
+
16
+ export interface BaseAndroidOptionsInterface {
17
+ buttonTextAlignment?: 'start' | 'center';
18
+ }
package/src/index.tsx CHANGED
@@ -3,6 +3,25 @@ import { Platform } from 'react-native';
3
3
  import type { Spec } from './NativeUnifiedActionSheet';
4
4
  import type { ActionSheetOptionsInterface } from './action-sheet-options.interface';
5
5
 
6
+ export type {
7
+ BaseButtonInterface,
8
+ BaseOptionsInterface,
9
+ BaseAndroidOptionsInterface,
10
+ } from './common-options.interface';
11
+
12
+ export type {
13
+ PromptButtonInterface,
14
+ PromptCommonOptionsInterface,
15
+ PromptAndroidOptionsInterface,
16
+ PromptOptionsInterface,
17
+ PromptResultInterface,
18
+ } from './prompt-options.interface';
19
+ import type { BaseButtonInterface } from './common-options.interface';
20
+ import type {
21
+ PromptOptionsInterface,
22
+ PromptResultInterface,
23
+ } from './prompt-options.interface';
24
+
6
25
  export type {
7
26
  ActionSheetAnchorInterface,
8
27
  ActionSheetButtonInterface,
@@ -34,13 +53,27 @@ const toWireOptions = ({
34
53
  // crosses the bridge. Omit<> would not strip it at runtime.
35
54
  anchor: _anchor,
36
55
  ...rest
37
- }: ActionSheetOptionsInterface): WireOptions => {
56
+ }: ActionSheetOptionsInterface): WireOptions => ({
57
+ ...rest,
58
+ ...toWireButtons(options),
59
+ });
60
+
61
+ type WirePromptOptions = Omit<PromptOptionsInterface, 'options'> & {
62
+ options: string[];
63
+ cancelButtonIndex?: number;
64
+ destructiveButtonIndices?: number[];
65
+ disabledButtonIndices?: number[];
66
+ };
67
+
68
+ /// Same flattening as the sheet: labels plus index sets. Kept generic over the
69
+ /// button shape so the two APIs cannot disagree about what 'cancel' means.
70
+ const toWireButtons = (buttons: ReadonlyArray<BaseButtonInterface>) => {
38
71
  const labels: string[] = [];
39
72
  const destructive: number[] = [];
40
73
  const disabled: number[] = [];
41
74
  let cancelButtonIndex: number | undefined;
42
75
 
43
- options.forEach((button, index) => {
76
+ buttons.forEach((button, index) => {
44
77
  labels.push(button.label);
45
78
 
46
79
  if (button.style === 'destructive') destructive.push(index);
@@ -51,7 +84,6 @@ const toWireOptions = ({
51
84
  });
52
85
 
53
86
  return {
54
- ...rest,
55
87
  options: labels,
56
88
  ...(cancelButtonIndex == null ? {} : { cancelButtonIndex }),
57
89
  ...(destructive.length === 0
@@ -129,3 +161,33 @@ export const dismissAllActionSheets = (): void => {
129
161
  nativeModule().dismissAllActionSheets();
130
162
  }
131
163
  };
164
+
165
+ /// A prompt is the sheet's centered dialog with a text field: iOS presents a
166
+ /// UIAlertController alert with addTextField, Android the same AppCompatDialog
167
+ /// the centered style uses. React Native's own Alert.prompt is iOS-only and a
168
+ /// silent no-op on Android, which is the gap this fills.
169
+ export const showPromptWithOptions = (
170
+ options: PromptOptionsInterface
171
+ ): Promise<PromptResultInterface | undefined> => {
172
+ const { options: buttons, ...rest } = options;
173
+ const wire: WirePromptOptions = { ...rest, ...toWireButtons(buttons) };
174
+
175
+ if (Platform.OS !== 'ios' && Platform.OS !== 'android') {
176
+ return Promise.resolve(undefined);
177
+ }
178
+
179
+ return nativeModule()
180
+ .showPromptWithOptions(wire)
181
+ .then((result) =>
182
+ // A programmatic dismiss resolves with no selection, matching the sheet.
183
+ result.buttonIndex === DISMISSED_BY_API ? undefined : result
184
+ )
185
+ .catch(() => ({ buttonIndex: wire.cancelButtonIndex ?? -1, text: '' }))
186
+ .then((result) => {
187
+ // The text goes to the handler, so a caller using onPress alone never
188
+ // has to read the resolved value.
189
+ if (result) buttons[result.buttonIndex]?.onPress?.(result.text);
190
+
191
+ return result;
192
+ });
193
+ };
@@ -0,0 +1,27 @@
1
+ import type {
2
+ BaseAndroidOptionsInterface,
3
+ BaseButtonInterface,
4
+ BaseOptionsInterface,
5
+ } from './common-options.interface';
6
+
7
+ export interface PromptButtonInterface extends BaseButtonInterface {
8
+ onPress?: (text: string) => void;
9
+ }
10
+
11
+ export interface PromptCommonOptionsInterface extends BaseOptionsInterface {
12
+ options: PromptButtonInterface[];
13
+ placeholder?: string;
14
+ defaultValue?: string;
15
+ keyboardType?: 'default' | 'email-address' | 'numeric' | 'phone-pad' | 'url';
16
+ secureTextEntry?: boolean;
17
+ }
18
+
19
+ export type PromptAndroidOptionsInterface = BaseAndroidOptionsInterface;
20
+
21
+ export interface PromptOptionsInterface
22
+ extends PromptCommonOptionsInterface, PromptAndroidOptionsInterface {}
23
+
24
+ export interface PromptResultInterface {
25
+ buttonIndex: number;
26
+ text: string;
27
+ }