@umituz/react-native-photo-editor 1.1.2 → 2.0.1
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.
- package/package.json +19 -13
- package/src/PhotoEditor.tsx +162 -44
- package/src/components/AIMagicSheet.tsx +54 -30
- package/src/components/AdjustmentsSheet.tsx +108 -0
- package/src/components/ColorPicker.tsx +77 -0
- package/src/components/DraggableSticker.tsx +92 -31
- package/src/components/DraggableText.tsx +98 -35
- package/src/components/EditorCanvas.tsx +38 -12
- package/src/components/EditorToolbar.tsx +130 -46
- package/src/components/FilterPicker.tsx +28 -21
- package/src/components/FontControls.tsx +68 -17
- package/src/components/LayerManager.tsx +112 -27
- package/src/components/Slider.tsx +112 -0
- package/src/components/StickerPicker.tsx +2 -1
- package/src/components/TextEditorSheet.tsx +113 -7
- package/src/constants.ts +63 -45
- package/src/core/HistoryManager.ts +11 -33
- package/src/hooks/useImagePicker.ts +69 -0
- package/src/hooks/usePhotoEditor.ts +73 -21
- package/src/hooks/usePhotoEditorUI.ts +103 -25
- package/src/index.ts +8 -0
- package/src/styles.ts +24 -6
- package/src/types.ts +12 -1
- package/src/utils/mediaUtils.ts +69 -0
- package/tsconfig.json +1 -1
package/src/types.ts
CHANGED
|
@@ -10,8 +10,17 @@ export interface ImageFilters {
|
|
|
10
10
|
saturation: number;
|
|
11
11
|
sepia: number;
|
|
12
12
|
grayscale: number;
|
|
13
|
+
hueRotate?: number; // 0-360 degrees
|
|
13
14
|
}
|
|
14
15
|
|
|
16
|
+
export const DEFAULT_IMAGE_FILTERS: ImageFilters = {
|
|
17
|
+
brightness: 1,
|
|
18
|
+
contrast: 1,
|
|
19
|
+
saturation: 1,
|
|
20
|
+
sepia: 0,
|
|
21
|
+
grayscale: 0,
|
|
22
|
+
};
|
|
23
|
+
|
|
15
24
|
export interface BaseLayer {
|
|
16
25
|
id: string;
|
|
17
26
|
x: number;
|
|
@@ -20,7 +29,7 @@ export interface BaseLayer {
|
|
|
20
29
|
scale: number;
|
|
21
30
|
opacity: number;
|
|
22
31
|
zIndex: number;
|
|
23
|
-
type: "text" | "sticker"
|
|
32
|
+
type: "text" | "sticker";
|
|
24
33
|
}
|
|
25
34
|
|
|
26
35
|
export interface TextLayer extends BaseLayer {
|
|
@@ -31,6 +40,8 @@ export interface TextLayer extends BaseLayer {
|
|
|
31
40
|
color: string;
|
|
32
41
|
backgroundColor: string;
|
|
33
42
|
textAlign: TextAlign;
|
|
43
|
+
isBold?: boolean;
|
|
44
|
+
isItalic?: boolean;
|
|
34
45
|
strokeColor?: string;
|
|
35
46
|
strokeWidth?: number;
|
|
36
47
|
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import * as MediaLibrary from "expo-media-library";
|
|
2
|
+
import { File, Paths } from "expo-file-system";
|
|
3
|
+
import { Share } from "react-native";
|
|
4
|
+
|
|
5
|
+
export interface SaveResult {
|
|
6
|
+
success: boolean;
|
|
7
|
+
uri?: string;
|
|
8
|
+
error?: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Save an image URI to the device's media library (Camera Roll / Photos).
|
|
13
|
+
* Requests permission if not already granted.
|
|
14
|
+
*/
|
|
15
|
+
export const saveToMediaLibrary = async (uri: string): Promise<SaveResult> => {
|
|
16
|
+
try {
|
|
17
|
+
const { status } = await MediaLibrary.requestPermissionsAsync();
|
|
18
|
+
if (status !== "granted") {
|
|
19
|
+
return { success: false, error: "Media library permission denied" };
|
|
20
|
+
}
|
|
21
|
+
const asset = await MediaLibrary.createAssetAsync(uri);
|
|
22
|
+
return { success: true, uri: asset.uri };
|
|
23
|
+
} catch (error) {
|
|
24
|
+
return { success: false, error: String(error) };
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Copy an image to the app's cache directory and return the local URI.
|
|
30
|
+
* Useful for temporary storage before sharing.
|
|
31
|
+
*/
|
|
32
|
+
export const copyToCacheDirectory = async (uri: string): Promise<string> => {
|
|
33
|
+
const fileName = `photo_editor_${Date.now()}.jpg`;
|
|
34
|
+
const destFile = new File(Paths.cache, fileName);
|
|
35
|
+
const srcFile = new File(uri);
|
|
36
|
+
srcFile.copy(destFile);
|
|
37
|
+
return destFile.uri;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Share an image using the native share sheet.
|
|
42
|
+
* @param uri - local file URI of the image
|
|
43
|
+
* @param message - optional text message to share alongside the image
|
|
44
|
+
*/
|
|
45
|
+
export const shareImage = async (
|
|
46
|
+
uri: string,
|
|
47
|
+
message?: string,
|
|
48
|
+
): Promise<void> => {
|
|
49
|
+
await Share.share({
|
|
50
|
+
url: uri,
|
|
51
|
+
message: message ?? "",
|
|
52
|
+
title: message,
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Delete a local file in the app's cache directory.
|
|
58
|
+
* Safe to call — will not throw even if the file doesn't exist.
|
|
59
|
+
*/
|
|
60
|
+
export const deleteLocalFile = async (uri: string): Promise<void> => {
|
|
61
|
+
try {
|
|
62
|
+
const file = new File(uri);
|
|
63
|
+
if (file.exists) {
|
|
64
|
+
file.delete();
|
|
65
|
+
}
|
|
66
|
+
} catch {
|
|
67
|
+
// silent — best-effort cleanup
|
|
68
|
+
}
|
|
69
|
+
};
|
package/tsconfig.json
CHANGED