Skip to content

Commit bed75ea

Browse files
committed
✨ feat: add more option for crop, ratio, default ratio for both platform
1 parent 604d85d commit bed75ea

File tree

4 files changed

+161
-2
lines changed

4 files changed

+161
-2
lines changed

docs/docs/CONFIG.mdx

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,59 @@ Maximum number of videos allowed.
8181
- **Required**: No
8282
- **Platform**: iOS, Android
8383

84-
### `crop`
84+
## Crop 🪚
8585

8686
Configuration for image cropping functionality.
8787

8888
- **Type**: object
8989
- **Default**: `undefined`
9090
- **Required**: No
9191
- **Platform**: iOS, Android
92+
93+
### `circle`
94+
95+
Enable circular crop mask.
96+
97+
- **Type**: boolean
98+
- **Default**: `false`
99+
- **Required**: No
100+
- **Platform**: iOS, Android
101+
102+
### `ratio`
103+
104+
Aspect ratios for cropping.
105+
Android: Maximum: 4 items
106+
107+
- **Type**: `array`
108+
- **Default**: `undefined`
109+
- **Required**: No
110+
- **Platform**: iOS, Android
92111
- **Properties**:
93-
- `circle`: boolean - Enable circular crop mask
112+
- `title`: string - Display title for the ratio (e.g., "Square", "16:9")
113+
- `width`: number - Width value for the aspect ratio
114+
- `height`: number - Height value for the aspect ratio
115+
116+
### `defaultRatio`
117+
118+
Default ratio to be selected when opening the crop interface.
119+
120+
- **Type**: `object`
121+
- **Default**: `undefined`
122+
- **Required**: No
123+
- **Platform**: iOS, Android
124+
- **Properties**:
125+
- `title`: string - Display title for the ratio (e.g., "Square", "16:9")
126+
- `width`: number - Width value for the aspect ratio
127+
- `height`: number - Height value for the aspect ratio
128+
129+
### `freeStyle`
130+
131+
Enable free style cropping.
132+
133+
- **Type**: `boolean`
134+
- **Default**: `false`
135+
- **Required**: No
136+
- **Platform**: iOS, Android
94137

95138
---
96139

docs/docs/CROP.mdx

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
---
2+
id: crop
3+
title: Crop
4+
sidebar_label: Crop
5+
slug: /crop
6+
---
7+
8+
## Usage
9+
10+
```typescript
11+
import { openCropper } from '@baronha/react-native-multiple-image-picker'
12+
13+
const cropConfig: CropConfig = {
14+
// ...
15+
}
16+
17+
const open = async () => {
18+
try {
19+
const response = await openCropper('file://path/to/image.jpg', cropConfig)
20+
setImages(response)
21+
} catch (e) {
22+
// catch error for multiple image picker
23+
}
24+
}
25+
```
26+
27+
## CropConfig
28+
29+
### `circle`
30+
31+
Enable circular crop mask.
32+
33+
- **Type**: boolean
34+
- **Default**: `false`
35+
- **Required**: No
36+
- **Platform**: iOS, Android
37+
38+
### `ratio`
39+
40+
Aspect ratios for cropping.
41+
Android: Maximum: 4 items
42+
43+
- **Type**: `array`
44+
- **Default**: `undefined`
45+
- **Required**: No
46+
- **Platform**: iOS, Android
47+
- **Properties**:
48+
- `title`: string - Display title for the ratio (e.g., "Square", "16:9")
49+
- `width`: number - Width value for the aspect ratio
50+
- `height`: number - Height value for the aspect ratio
51+
52+
### `defaultRatio`
53+
54+
Default ratio to be selected when opening the crop interface.
55+
56+
- **Type**: `object`
57+
- **Default**: `undefined`
58+
- **Required**: No
59+
- **Platform**: iOS, Android
60+
- **Properties**:
61+
- `title`: string - Display title for the ratio (e.g., "Square", "16:9")
62+
- `width`: number - Width value for the aspect ratio
63+
- `height`: number - Height value for the aspect ratio
64+
65+
### `freeStyle`
66+
67+
Enable free style cropping.
68+
69+
- **Type**: `boolean`
70+
- **Default**: `false`
71+
- **Required**: No
72+
- **Platform**: iOS, Android
73+
74+
### `language`
75+
76+
- **Type**: `string`
77+
- **Default**: `false`
78+
- **Required**: No
79+
- **Platform**: iOS
80+
81+
See [**Language**](/config/#language)
82+
83+
## Result
84+
85+
### `path`
86+
87+
- **Type**: `string`
88+
89+
### `width`
90+
91+
- **Type**: `number`
92+
93+
### `height`
94+
95+
- **Type**: `number`

docs/sidebars.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ const sidebars: SidebarsConfig = {
2323
},
2424
items: ['getting-started', 'usage', 'config', 'result'],
2525
},
26+
27+
'crop',
2628
],
2729
}
2830

ios/TopViewController.swift

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// UIViewController+TopViewController.swift
3+
// Pods
4+
//
5+
// Created by BAO HA on 11/12/24.
6+
//
7+
8+
import UIKit
9+
10+
extension UIViewController {
11+
func topViewController() -> UIViewController? {
12+
var controller = UIApplication.shared.keyWindow?.rootViewController
13+
while let presentedViewController = controller?.presentedViewController {
14+
controller = presentedViewController
15+
}
16+
17+
return controller
18+
}
19+
}

0 commit comments

Comments
 (0)