@phucprime/react-native-image-editor 1.0.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 (85) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +247 -0
  3. package/android/build.gradle +62 -0
  4. package/android/gradle/wrapper/gradle-wrapper.jar +0 -0
  5. package/android/gradle/wrapper/gradle-wrapper.properties +5 -0
  6. package/android/gradlew +240 -0
  7. package/android/gradlew.bat +91 -0
  8. package/android/libs/photo-editor-android.jar +0 -0
  9. package/android/src/main/AndroidManifest.xml +5 -0
  10. package/android/src/main/java/com/ahmedadeltito/photoeditor/BaseActivity.java +300 -0
  11. package/android/src/main/java/com/ahmedadeltito/photoeditor/ColorPickerAdapter.java +129 -0
  12. package/android/src/main/java/com/ahmedadeltito/photoeditor/EmojiAdapter.java +91 -0
  13. package/android/src/main/java/com/ahmedadeltito/photoeditor/EmojiFragment.java +56 -0
  14. package/android/src/main/java/com/ahmedadeltito/photoeditor/GalleryUtils.java +73 -0
  15. package/android/src/main/java/com/ahmedadeltito/photoeditor/ImageAdapter.java +69 -0
  16. package/android/src/main/java/com/ahmedadeltito/photoeditor/ImageFragment.java +93 -0
  17. package/android/src/main/java/com/ahmedadeltito/photoeditor/MainActivity.java +29 -0
  18. package/android/src/main/java/com/ahmedadeltito/photoeditor/MediaActivity.java +95 -0
  19. package/android/src/main/java/com/ahmedadeltito/photoeditor/PhotoEditorActivity.java +1055 -0
  20. package/android/src/main/java/com/ahmedadeltito/photoeditor/TranslationService.java +31 -0
  21. package/android/src/main/java/com/ahmedadeltito/photoeditor/UtilFunctions.java +176 -0
  22. package/android/src/main/java/com/ahmedadeltito/photoeditor/widget/RealtimeBlurView.java +359 -0
  23. package/android/src/main/java/com/ahmedadeltito/photoeditor/widget/SlidingUpPanelLayout.java +1527 -0
  24. package/android/src/main/java/com/ahmedadeltito/photoeditor/widget/ViewDragHelper.java +1466 -0
  25. package/android/src/main/java/ui/photoeditor/RNPhotoEditorModule.java +108 -0
  26. package/android/src/main/java/ui/photoeditor/RNPhotoEditorPackage.java +29 -0
  27. package/android/src/main/res/drawable/above_shadow.xml +7 -0
  28. package/android/src/main/res/drawable/below_shadow.xml +7 -0
  29. package/android/src/main/res/drawable/fading_shadow.xml +7 -0
  30. package/android/src/main/res/drawable/rounded_border_text_view.xml +13 -0
  31. package/android/src/main/res/drawable-xhdpi/aa.png +0 -0
  32. package/android/src/main/res/drawable-xhdpi/bb.png +0 -0
  33. package/android/src/main/res/drawable-xhdpi/c.png +0 -0
  34. package/android/src/main/res/drawable-xhdpi/cc.png +0 -0
  35. package/android/src/main/res/drawable-xhdpi/d.png +0 -0
  36. package/android/src/main/res/drawable-xhdpi/dd.png +0 -0
  37. package/android/src/main/res/drawable-xhdpi/e.png +0 -0
  38. package/android/src/main/res/drawable-xhdpi/ee.png +0 -0
  39. package/android/src/main/res/drawable-xhdpi/i.png +0 -0
  40. package/android/src/main/res/drawable-xhdpi/j.png +0 -0
  41. package/android/src/main/res/drawable-xhdpi/k.png +0 -0
  42. package/android/src/main/res/drawable-xhdpi/l.png +0 -0
  43. package/android/src/main/res/drawable-xhdpi/m.png +0 -0
  44. package/android/src/main/res/drawable-xhdpi/n.png +0 -0
  45. package/android/src/main/res/drawable-xhdpi/o.png +0 -0
  46. package/android/src/main/res/drawable-xhdpi/p.png +0 -0
  47. package/android/src/main/res/drawable-xhdpi/q.png +0 -0
  48. package/android/src/main/res/drawable-xhdpi/r.png +0 -0
  49. package/android/src/main/res/drawable-xhdpi/s.png +0 -0
  50. package/android/src/main/res/drawable-xhdpi/t.png +0 -0
  51. package/android/src/main/res/drawable-xhdpi/u.png +0 -0
  52. package/android/src/main/res/drawable-xhdpi/v.png +0 -0
  53. package/android/src/main/res/drawable-xhdpi/w.png +0 -0
  54. package/android/src/main/res/drawable-xhdpi/x.png +0 -0
  55. package/android/src/main/res/drawable-xhdpi/y.png +0 -0
  56. package/android/src/main/res/drawable-xhdpi/z.png +0 -0
  57. package/android/src/main/res/layout/activity_main.xml +28 -0
  58. package/android/src/main/res/layout/activity_photo_editor.xml +316 -0
  59. package/android/src/main/res/layout/add_text_popup_window.xml +47 -0
  60. package/android/src/main/res/layout/color_picker_item_list.xml +15 -0
  61. package/android/src/main/res/layout/fragment_main_photo_edit_emoji.xml +11 -0
  62. package/android/src/main/res/layout/fragment_main_photo_edit_image.xml +10 -0
  63. package/android/src/main/res/layout/fragment_photo_edit_emoji_item_list.xml +17 -0
  64. package/android/src/main/res/layout/fragment_photo_edit_image_item_list.xml +16 -0
  65. package/android/src/main/res/raw/emojioneandroid +0 -0
  66. package/android/src/main/res/raw/eventtusicons +0 -0
  67. package/android/src/main/res/raw/font_awesome_solid.otf +0 -0
  68. package/android/src/main/res/raw/icomoon.ttf +0 -0
  69. package/android/src/main/res/values/arrays.xml +447 -0
  70. package/android/src/main/res/values/attrs.xml +30 -0
  71. package/android/src/main/res/values/colors.xml +21 -0
  72. package/android/src/main/res/values/dimens.xml +4 -0
  73. package/android/src/main/res/values/strings.xml +33 -0
  74. package/android/src/main/res/values/styles.xml +27 -0
  75. package/ios/RNImageEditor.podspec +26 -0
  76. package/ios/RNPhotoEditor.h +13 -0
  77. package/ios/RNPhotoEditor.m +163 -0
  78. package/ios/RNPhotoEditor.xcodeproj/project.pbxproj +362 -0
  79. package/lib/index.d.ts +125 -0
  80. package/lib/index.d.ts.map +1 -0
  81. package/lib/index.js +114 -0
  82. package/lib/index.js.map +1 -0
  83. package/package.json +73 -0
  84. package/react-native-image-editor.podspec +39 -0
  85. package/src/index.ts +232 -0
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAIA;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,kCAAkC;IAClC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uCAAuC;IACvC,aAAa,CAAC,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AACH,cAAM,WAAW;IACf;;;;OAIG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;IAgC5C;;;;;;OAMG;IACH,MAAM,CAAC,IAAI,CACT,IAAI,EAAE,MAAM,EACZ,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,EAAE,MAAM,GAAG,QAAQ,GAAG,UAAU,CAAC,GAChE,OAAO,CAAC,MAAM,CAAC;IAYlB;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,MAAM,EAAE,iBAAiB,GAAG,IAAI;CAG7C;AAED;;GAEG;AACH,QAAA,MAAM,WAAW,oBAAc,CAAC;AAEhC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,CAAC;AACpC,eAAe,WAAW,CAAC;AAG3B,mDAAmD;AACnD,MAAM,MAAM,gBAAgB,GAAG,iBAAiB,CAAC;AACjD,qDAAqD;AACrD,MAAM,MAAM,QAAQ,GAAG,mBAAmB,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ var __rest = (this && this.__rest) || function (s, e) {
3
+ var t = {};
4
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
5
+ t[p] = s[p];
6
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
7
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
8
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
9
+ t[p[i]] = s[p[i]];
10
+ }
11
+ return t;
12
+ };
13
+ Object.defineProperty(exports, "__esModule", { value: true });
14
+ exports.PhotoEditor = exports.ImageEditor = void 0;
15
+ const react_native_1 = require("react-native");
16
+ const { RNPhotoEditor } = react_native_1.NativeModules;
17
+ /** Default color palette for the editor. */
18
+ const DEFAULT_COLORS = [
19
+ '#000000',
20
+ '#808080',
21
+ '#a9a9a9',
22
+ '#FFFFFE',
23
+ '#0000ff',
24
+ '#00ff00',
25
+ '#ff0000',
26
+ '#ffff00',
27
+ '#ffa500',
28
+ '#800080',
29
+ '#00ffff',
30
+ '#a52a2a',
31
+ '#ff00ff',
32
+ ];
33
+ /** Default localization strings. */
34
+ const DEFAULT_LANGUAGES = {
35
+ doneTitle: 'Done',
36
+ saveTitle: 'Save',
37
+ clearAllTitle: 'Clear all',
38
+ cameraTitle: 'Camera',
39
+ galleryTitle: 'Gallery',
40
+ uploadDialogTitle: 'Upload Image',
41
+ uploadPickerTitle: 'Select Picture',
42
+ directoryCreateFail: 'Failed to create directory',
43
+ accessMediaPermissionsMsg: 'To attach photos, we need to access media on your device',
44
+ continueTxt: 'Continue',
45
+ notNow: 'NOT NOW',
46
+ mediaAccessDeniedMsg: 'You denied storage access, no photos will be added.',
47
+ saveImageSucceed: 'Image saved',
48
+ eraserTitle: 'Eraser',
49
+ };
50
+ /**
51
+ * React Native Image Editor - Native photo editing bridge for iOS and Android.
52
+ *
53
+ * @example
54
+ * ```ts
55
+ * import { ImageEditor } from '@phucprime/react-native-image-editor';
56
+ *
57
+ * // Callback-based usage
58
+ * ImageEditor.open({
59
+ * path: '/path/to/image.jpg',
60
+ * onDone: (editedPath) => console.log('Edited:', editedPath),
61
+ * onCancel: () => console.log('Cancelled'),
62
+ * });
63
+ *
64
+ * // Promise-based usage
65
+ * const editedPath = await ImageEditor.edit('/path/to/image.jpg', {
66
+ * colors: ['#ff0000', '#00ff00', '#0000ff'],
67
+ * });
68
+ * ```
69
+ */
70
+ class ImageEditor {
71
+ /**
72
+ * Open the image editor with callback-based API.
73
+ *
74
+ * @param config - Editor configuration options.
75
+ */
76
+ static open(config) {
77
+ const { stickers = [], hiddenControls = [], colors = DEFAULT_COLORS, languages, onDone, onCancel } = config, rest = __rest(config, ["stickers", "hiddenControls", "colors", "languages", "onDone", "onCancel"]);
78
+ const mergedLanguages = languages
79
+ ? Object.assign(Object.assign({}, DEFAULT_LANGUAGES), languages) : DEFAULT_LANGUAGES;
80
+ RNPhotoEditor.Edit(Object.assign({ colors,
81
+ hiddenControls,
82
+ stickers, languages: mergedLanguages }, rest), (imagePath) => {
83
+ onDone === null || onDone === void 0 ? void 0 : onDone(imagePath);
84
+ }, (resultCode) => {
85
+ onCancel === null || onCancel === void 0 ? void 0 : onCancel(resultCode);
86
+ });
87
+ }
88
+ /**
89
+ * Edit an image and return a promise with the edited image path.
90
+ *
91
+ * @param path - Path to the image file to edit.
92
+ * @param options - Optional editor configuration (excluding path, onDone, onCancel).
93
+ * @returns Promise that resolves with the edited image path, or rejects if cancelled.
94
+ */
95
+ static edit(path, options) {
96
+ return new Promise((resolve, reject) => {
97
+ ImageEditor.open(Object.assign(Object.assign({}, options), { path, onDone: resolve, onCancel: (resultCode) => reject(new Error(`Editor cancelled with code: ${resultCode}`)) }));
98
+ });
99
+ }
100
+ /**
101
+ * @deprecated Use `ImageEditor.open()` instead. This method is kept for backward compatibility.
102
+ */
103
+ static Edit(config) {
104
+ ImageEditor.open(config);
105
+ }
106
+ }
107
+ exports.ImageEditor = ImageEditor;
108
+ /**
109
+ * @deprecated Use `ImageEditor` instead. `PhotoEditor` is an alias kept for backward compatibility.
110
+ */
111
+ const PhotoEditor = ImageEditor;
112
+ exports.PhotoEditor = PhotoEditor;
113
+ exports.default = ImageEditor;
114
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;AAAA,+CAAuD;AAEvD,MAAM,EAAE,aAAa,EAAE,GAAG,4BAAa,CAAC;AA4FxC,4CAA4C;AAC5C,MAAM,cAAc,GAAa;IAC/B,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;IACT,SAAS;CACV,CAAC;AAEF,oCAAoC;AACpC,MAAM,iBAAiB,GAAkC;IACvD,SAAS,EAAE,MAAM;I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O,KACV,IAAI,EACJ,MAAM,EAAE,OAAO,EACf,QAAQ,EAAE,CAAC,UAAU,EAAE,EAAE,CACvB,MAAM,CAAC,IAAI,KAAK,CAAC,+BAA+B,UAAU,EAAE,CAAC,CAAC,IAChE,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,IAAI,CAAC,MAAyB;QACnC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3B,CAAC;CACF;AAOQ,kCAAW;AALpB;;GAEG;AACH,MAAM,WAAW,GAAG,WAAW,CAAC;AAEV,kCAAW;AACjC,kBAAe,WAAW,CAAC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@phucprime/react-native-image-editor",
3
+ "version": "1.0.0",
4
+ "description": "React Native: Native Image Editor for iOS and Android with drawing, text, stickers, cropping and more",
5
+ "main": "lib/index.js",
6
+ "types": "lib/index.d.ts",
7
+ "react-native": "src/index",
8
+ "source": "src/index.ts",
9
+ "files": [
10
+ "src/",
11
+ "lib/",
12
+ "ios/",
13
+ "android/",
14
+ "react-native-image-editor.podspec",
15
+ "!android/build/",
16
+ "!ios/build/",
17
+ "!**/__tests__/"
18
+ ],
19
+ "homepage": "https://github.com/phucprime/react-native-image-editor#readme",
20
+ "repository": {
21
+ "type": "git",
22
+ "url": "git+https://github.com/phucprime/react-native-image-editor.git"
23
+ },
24
+ "bugs": {
25
+ "url": "https://github.com/phucprime/react-native-image-editor/issues"
26
+ },
27
+ "scripts": {
28
+ "build": "tsc --project tsconfig.build.json",
29
+ "typecheck": "tsc --noEmit",
30
+ "lint": "prettier --check src/",
31
+ "format": "prettier --write src/",
32
+ "clean": "rm -rf lib/",
33
+ "prepare": "npm run clean && npm run build",
34
+ "release": "npm run prepare && npm publish --access public"
35
+ },
36
+ "keywords": [
37
+ "react-native",
38
+ "image-editor",
39
+ "photo-editor",
40
+ "image",
41
+ "photo",
42
+ "editor",
43
+ "crop",
44
+ "draw",
45
+ "sticker",
46
+ "text",
47
+ "ios",
48
+ "android"
49
+ ],
50
+ "author": "phucprime",
51
+ "license": "Apache-2.0",
52
+ "peerDependencies": {
53
+ "react": ">=16.8.0",
54
+ "react-native": ">=0.60.0"
55
+ },
56
+ "peerDependenciesMeta": {
57
+ "react": {
58
+ "optional": false
59
+ },
60
+ "react-native": {
61
+ "optional": false
62
+ }
63
+ },
64
+ "devDependencies": {
65
+ "@types/react": "^18.2.0",
66
+ "@types/react-native": "^0.72.0",
67
+ "prettier": "^3.2.0",
68
+ "typescript": "^5.3.0"
69
+ },
70
+ "engines": {
71
+ "node": ">=16.0.0"
72
+ }
73
+ }
@@ -0,0 +1,39 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "react-native-image-editor"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+ s.platforms = { :ios => "13.0" }
13
+ s.source = { :git => "https://github.com/phucprime/react-native-image-editor.git", :tag => "#{s.version}" }
14
+
15
+ s.source_files = "ios/**/*.{h,m,mm}"
16
+ s.dependency "iOSPhotoEditor"
17
+
18
+ # Use install_modules_dependencies helper to install the dependencies if React Native version >=0.71.0.
19
+ if respond_to?(:install_modules_dependencies, true)
20
+ install_modules_dependencies(s)
21
+ else
22
+ s.dependency "React-Core"
23
+
24
+ # Don't install the dependencies when we run `pod install` in the old architecture.
25
+ if ENV["RCT_NEW_ARCH_ENABLED"] == "1"
26
+ s.compiler_flags = folly_compiler_flags + " -DRCT_NEW_ARCH_ENABLED=1"
27
+ s.pod_target_xcconfig = {
28
+ "HEADER_SEARCH_PATHS" => "\"$(PODS_ROOT)/boost\"",
29
+ "OTHER_CPLUSPLUSFLAGS" => "-DFOLLY_NO_CONFIG -DFOLLY_MOBILE=1 -DFOLLY_USE_LIBCPP=1",
30
+ "CLANG_CXX_LANGUAGE_STANDARD" => "c++17",
31
+ }
32
+ s.dependency "React-Codegen"
33
+ s.dependency "RCT-Folly"
34
+ s.dependency "RCTRequired"
35
+ s.dependency "RCTTypeSafety"
36
+ s.dependency "ReactCommon/turbomodule/core"
37
+ end
38
+ end
39
+ end
package/src/index.ts ADDED
@@ -0,0 +1,232 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+
3
+ const { RNPhotoEditor } = NativeModules;
4
+
5
+ /**
6
+ * Localization strings for the image editor UI.
7
+ */
8
+ export interface ImageEditorLanguage {
9
+ /** Title for the "Done" button */
10
+ doneTitle?: string;
11
+ /** Title for the "Save" button */
12
+ saveTitle?: string;
13
+ /** Title for the "Clear All" button */
14
+ clearAllTitle?: string;
15
+ /** Title for the "Camera" option */
16
+ cameraTitle?: string;
17
+ /** Title for the "Gallery" option */
18
+ galleryTitle?: string;
19
+ /** Title for the upload dialog */
20
+ uploadDialogTitle?: string;
21
+ /** Title for the upload picker */
22
+ uploadPickerTitle?: string;
23
+ /** Message shown when directory creation fails */
24
+ directoryCreateFail?: string;
25
+ /** Message requesting media access permissions */
26
+ accessMediaPermissionsMsg?: string;
27
+ /** Label for the "Continue" button */
28
+ continueTxt?: string;
29
+ /** Label for the "Not Now" button */
30
+ notNow?: string;
31
+ /** Message shown when media access is denied */
32
+ mediaAccessDeniedMsg?: string;
33
+ /** Message shown when image save succeeds */
34
+ saveImageSucceed?: string;
35
+ /** Title for the "Eraser" tool */
36
+ eraserTitle?: string;
37
+ }
38
+
39
+ /** Editor control types that can be shown or hidden. */
40
+ export type EditorControl =
41
+ | 'text'
42
+ | 'clear'
43
+ | 'draw'
44
+ | 'save'
45
+ | 'share'
46
+ | 'sticker'
47
+ | 'crop';
48
+
49
+ /**
50
+ * Configuration options for the image editor.
51
+ */
52
+ export interface ImageEditorConfig {
53
+ /** Path to the image file to edit (required). */
54
+ path: string;
55
+
56
+ /**
57
+ * Array of hex color strings available for drawing and text.
58
+ * @default ['#000000', '#808080', '#a9a9a9', '#FFFFFE', '#0000ff', '#00ff00', '#ff0000', '#ffff00', '#ffa500', '#800080', '#00ffff', '#a52a2a', '#ff00ff']
59
+ */
60
+ colors?: string[];
61
+
62
+ /**
63
+ * Array of sticker image names to show in the sticker picker.
64
+ * Images must be added to native project resources.
65
+ * - iOS: Add to Resources folder
66
+ * - Android: Add to drawable folder
67
+ * @default []
68
+ */
69
+ stickers?: string[];
70
+
71
+ /**
72
+ * Array of editor controls to hide.
73
+ * @default []
74
+ */
75
+ hiddenControls?: EditorControl[];
76
+
77
+ /**
78
+ * Localization strings for the editor UI.
79
+ */
80
+ languages?: ImageEditorLanguage;
81
+
82
+ /**
83
+ * Callback invoked when editing is complete.
84
+ * @param imagePath - The path to the edited image file.
85
+ */
86
+ onDone?: (imagePath: string) => void;
87
+
88
+ /**
89
+ * Callback invoked when editing is cancelled.
90
+ * @param resultCode - The native result code.
91
+ */
92
+ onCancel?: (resultCode: number) => void;
93
+ }
94
+
95
+ /** Default color palette for the editor. */
96
+ const DEFAULT_COLORS: string[] = [
97
+ '#000000',
98
+ '#808080',
99
+ '#a9a9a9',
100
+ '#FFFFFE',
101
+ '#0000ff',
102
+ '#00ff00',
103
+ '#ff0000',
104
+ '#ffff00',
105
+ '#ffa500',
106
+ '#800080',
107
+ '#00ffff',
108
+ '#a52a2a',
109
+ '#ff00ff',
110
+ ];
111
+
112
+ /** Default localization strings. */
113
+ const DEFAULT_LANGUAGES: Required<ImageEditorLanguage> = {
114
+ doneTitle: 'Done',
115
+ saveTitle: 'Save',
116
+ clearAllTitle: 'Clear all',
117
+ cameraTitle: 'Camera',
118
+ galleryTitle: 'Gallery',
119
+ uploadDialogTitle: 'Upload Image',
120
+ uploadPickerTitle: 'Select Picture',
121
+ directoryCreateFail: 'Failed to create directory',
122
+ accessMediaPermissionsMsg:
123
+ 'To attach photos, we need to access media on your device',
124
+ continueTxt: 'Continue',
125
+ notNow: 'NOT NOW',
126
+ mediaAccessDeniedMsg:
127
+ 'You denied storage access, no photos will be added.',
128
+ saveImageSucceed: 'Image saved',
129
+ eraserTitle: 'Eraser',
130
+ };
131
+
132
+ /**
133
+ * React Native Image Editor - Native photo editing bridge for iOS and Android.
134
+ *
135
+ * @example
136
+ * ```ts
137
+ * import { ImageEditor } from '@phucprime/react-native-image-editor';
138
+ *
139
+ * // Callback-based usage
140
+ * ImageEditor.open({
141
+ * path: '/path/to/image.jpg',
142
+ * onDone: (editedPath) => console.log('Edited:', editedPath),
143
+ * onCancel: () => console.log('Cancelled'),
144
+ * });
145
+ *
146
+ * // Promise-based usage
147
+ * const editedPath = await ImageEditor.edit('/path/to/image.jpg', {
148
+ * colors: ['#ff0000', '#00ff00', '#0000ff'],
149
+ * });
150
+ * ```
151
+ */
152
+ class ImageEditor {
153
+ /**
154
+ * Open the image editor with callback-based API.
155
+ *
156
+ * @param config - Editor configuration options.
157
+ */
158
+ static open(config: ImageEditorConfig): void {
159
+ const {
160
+ stickers = [],
161
+ hiddenControls = [],
162
+ colors = DEFAULT_COLORS,
163
+ languages,
164
+ onDone,
165
+ onCancel,
166
+ ...rest
167
+ } = config;
168
+
169
+ const mergedLanguages = languages
170
+ ? { ...DEFAULT_LANGUAGES, ...languages }
171
+ : DEFAULT_LANGUAGES;
172
+
173
+ RNPhotoEditor.Edit(
174
+ {
175
+ colors,
176
+ hiddenControls,
177
+ stickers,
178
+ languages: mergedLanguages,
179
+ ...rest,
180
+ },
181
+ (imagePath: string) => {
182
+ onDone?.(imagePath);
183
+ },
184
+ (resultCode: number) => {
185
+ onCancel?.(resultCode);
186
+ },
187
+ );
188
+ }
189
+
190
+ /**
191
+ * Edit an image and return a promise with the edited image path.
192
+ *
193
+ * @param path - Path to the image file to edit.
194
+ * @param options - Optional editor configuration (excluding path, onDone, onCancel).
195
+ * @returns Promise that resolves with the edited image path, or rejects if cancelled.
196
+ */
197
+ static edit(
198
+ path: string,
199
+ options?: Omit<ImageEditorConfig, 'path' | 'onDone' | 'onCancel'>,
200
+ ): Promise<string> {
201
+ return new Promise((resolve, reject) => {
202
+ ImageEditor.open({
203
+ ...options,
204
+ path,
205
+ onDone: resolve,
206
+ onCancel: (resultCode) =>
207
+ reject(new Error(`Editor cancelled with code: ${resultCode}`)),
208
+ });
209
+ });
210
+ }
211
+
212
+ /**
213
+ * @deprecated Use `ImageEditor.open()` instead. This method is kept for backward compatibility.
214
+ */
215
+ static Edit(config: ImageEditorConfig): void {
216
+ ImageEditor.open(config);
217
+ }
218
+ }
219
+
220
+ /**
221
+ * @deprecated Use `ImageEditor` instead. `PhotoEditor` is an alias kept for backward compatibility.
222
+ */
223
+ const PhotoEditor = ImageEditor;
224
+
225
+ export { ImageEditor, PhotoEditor };
226
+ export default ImageEditor;
227
+
228
+ // Re-export legacy types for backward compatibility
229
+ /** @deprecated Use `ImageEditorConfig` instead. */
230
+ export type PhotoEditorProps = ImageEditorConfig;
231
+ /** @deprecated Use `ImageEditorLanguage` instead. */
232
+ export type Language = ImageEditorLanguage;