@@ -14,6 +14,10 @@ import Checkbox from "expo-checkbox";
14
14
import { validateAppVersion } from '@/utils/validateAppVersion' ;
15
15
import ColorPickerModel from '@/components/colorPickerModel' ;
16
16
import { rewarded } from '@/ads/reward' ;
17
+ import EffectImagePreview from '@/components/common/effectImagePreview' ;
18
+ import PromptComponent from '@/components/common/promptComponent' ;
19
+ import CustomCheckBox from '@/components/common/customCheckBox' ;
20
+ import ActionButtons from '@/components/common/actionButtons' ;
17
21
18
22
19
23
const GenerativeRecolor = ( ) => {
@@ -25,7 +29,7 @@ const GenerativeRecolor = () => {
25
29
const [ transformedImageUrl , setTransformedImageUrl ] = useState < string | undefined > ( undefined )
26
30
const [ loadingMessage , setLoadingMessage ] = useState ( "" ) ;
27
31
const { allowAds } = useContext ( GlobalContext ) ;
28
-
32
+ const [ buttonText , setButtonText ] = useState ( "Recolor" ) ;
29
33
const getPicture = async ( ) => {
30
34
const asset = await getAssetFromGallery ( { fileType : "image" } ) ;
31
35
setImg ( asset )
@@ -70,7 +74,7 @@ const GenerativeRecolor = () => {
70
74
return ;
71
75
}
72
76
73
- if ( items . length === 0 ) {
77
+ if ( items . length === 0 && prompt . trim ( ) . length === 0 ) {
74
78
Alert . alert ( "Prompt Missing" , "Select at least one item to recolor" ) ;
75
79
return ;
76
80
}
@@ -80,7 +84,13 @@ const GenerativeRecolor = () => {
80
84
await validateAppVersion ( ) ;
81
85
// remove the hast from the start.
82
86
const color = colorPicked . slice ( 1 ) ;
83
- const promptToSend = items . length === 1 ? items . join ( "" ) : `(${ items . join ( ";" ) } )` ;
87
+ let promptToSend ;
88
+
89
+ if ( items . length == 0 ) {
90
+ promptToSend = `(${ prompt } )` ;
91
+ } else {
92
+ promptToSend = items . length === 1 ? items . join ( "" ) : `(${ items . join ( ";" ) } )` ;
93
+ }
84
94
85
95
86
96
if ( allowAds && rewarded . loaded ) {
@@ -116,53 +126,27 @@ const GenerativeRecolor = () => {
116
126
return (
117
127
< View className = 'bg-background h-full px-[10px]' >
118
128
< ScrollView >
119
- < Text style = { { fontFamily : "Outfit-Medium" } } className = 'text-text text-3xl my-7' > Generative Recolor</ Text >
120
-
121
- {
122
-
123
- < TouchableOpacity onPress = { getPicture } activeOpacity = { 0.5 } className = 'bg-[#1D1B20] h-[280px] relative items-center rounded-[10px] justify-center' >
124
-
125
- < Image
126
- onLoadStart = { ( ) => setLoadingMessage ( "Generative recolor in progress..." ) }
127
- onLoad = { ( ) => setLoadingMessage ( "" ) }
128
- onError = { ( ) => {
129
- setLoadingMessage ( "" )
130
- Alert . alert ( "Error" , "something went wrong while loading images. try again later" ) ;
131
- setTransformedImageUrl ( undefined )
132
- } }
133
- resizeMode = { "contain" }
134
- className = { `w-full absolute top-0 left-0 h-full ${ loadingMessage ? "opacity-0" : "opacity-100" } ` }
135
- source = { transformedImageUrl
136
- ? { uri : transformedImageUrl }
137
- : img ?. uri
138
- ? { uri : img . uri }
139
- : require ( "@/assets/images/transparent.png" ) }
140
- />
141
-
142
- < View className = { `items-center absolute top-1/3 left-1/3 z-0 gap-y-2 ${ ( img || transformedImageUrl ) ? "hidden" : "" } ` } >
143
- < Svg width = "32" height = "41" viewBox = "0 0 32 41" fill = "" >
144
- < Path d = "M20 0.5H4C1.8 0.5 0 2.3 0 4.5V36.5C0 38.7 1.8 40.5 4 40.5H28C30.2 40.5 32 38.7 32 36.5V12.5L20 0.5ZM6 32.5L11 25.834L14 29.834L19 23.168L26 32.5H6ZM18 14.5V3.5L29 14.5H18Z" fill = "#e5e7eb" />
145
- </ Svg >
146
- < Text style = { { fontFamily : "Outfit-Medium" } } className = 'text-gray-200 text-xl' > Select Image</ Text >
147
- </ View >
148
-
149
-
150
- < LoadingWithMessage message = { loadingMessage } />
151
- </ TouchableOpacity >
152
- }
129
+ < EffectImagePreview
130
+ getPicture = { getPicture }
131
+ effectTitle = { "Generative Recolor" }
132
+ image = { img }
133
+ originalButtonText = 'Recolor'
134
+ setButtonText = { setButtonText }
135
+ loadingMessage = { loadingMessage }
136
+ setLoadingMessage = { setLoadingMessage }
137
+ transformedImageUrl = { transformedImageUrl }
138
+ setTransformedImageUrl = { setTransformedImageUrl }
153
139
140
+ />
154
141
155
- { /* prompt Area */ }
156
- < TextInput
157
- value = { prompt }
158
- onChangeText = { ( e ) => {
142
+ < PromptComponent
143
+ promptValue = { prompt }
144
+ style = 'mt-8 h-12 px-2 bg-backgroundContainer text-gray-200 focus:border-2 rounded-md focus:border-outline'
145
+ onPromptChange = { ( e : string ) => {
159
146
handleItems ( e )
160
147
setTransformedImageUrl ( "" ) ;
161
148
} }
162
- numberOfLines = { 3 }
163
149
placeholder = { items . length === 0 ? 'Items to recolor separate my comma. (3 max)' : items . length >= 3 ? "Max items selected" : "New items" }
164
- className = 'mt-8 h-12 px-2 bg-backgroundContainer text-gray-200 focus:border-2 rounded-md focus:border-outline'
165
- placeholderTextColor = { "#65558F" }
166
150
/>
167
151
168
152
{ /* items to recolor */ }
@@ -186,24 +170,17 @@ const GenerativeRecolor = () => {
186
170
187
171
188
172
< View className = 'flex-row justify-between items-center mt-4 gap-x-3' >
189
- < TouchableOpacity
190
- onPress = { ( ) => {
191
- setMultiple ( prev => ! prev ) ;
192
- setTransformedImageUrl ( "" ) ;
193
- } }
194
- activeOpacity = { 1 }
195
- className = 'flex-row py-1.5 items-center'
196
- >
197
- < Checkbox
198
- value = { multiple }
199
- onValueChange = { ( ) => {
200
- setMultiple ( prev => ! prev ) ;
201
- setTransformedImageUrl ( "" ) ;
173
+ < View >
174
+ < CustomCheckBox
175
+ checked = { multiple }
176
+ style = 'pl-3'
177
+ onChecked = { ( ) => {
178
+ setMultiple ( prev => ! prev )
179
+ transformedImageUrl && setTransformedImageUrl ( "" ) ;
202
180
} }
203
- color = { multiple ? "#326AFD" : "white "}
181
+ label = { "Recolor Multiple "}
204
182
/>
205
- < Text className = 'text-text ml-2' > Recolor multiple</ Text >
206
- </ TouchableOpacity >
183
+ </ View >
207
184
208
185
209
186
< View className = 'w-1/2 h-full flex-row justify-end gap-x-3 items-center' >
@@ -213,16 +190,11 @@ const GenerativeRecolor = () => {
213
190
</ View >
214
191
215
192
{ /* buttons */ }
216
- < View className = 'flex-row justify-between items-center mt-4' >
217
- < Link href = { ".." } asChild >
218
- < TouchableOpacity activeOpacity = { 0.5 } className = 'border-2 border-buttonBackground h-[50px] rounded-md justify-center items-center max-w-40 w-[48%]' >
219
- < Text style = { { fontFamily : "Poppins-SemiBold" } } className = 'text-text text-sm' > Cancel</ Text >
220
- </ TouchableOpacity >
221
- </ Link >
222
- < TouchableOpacity onPress = { handleTransformation } activeOpacity = { 0.5 } className = 'bg-buttonBackground h-[50px] rounded-md justify-center items-center max-w-40 w-[48%]' >
223
- < Text style = { { fontFamily : "Poppins-SemiBold" } } className = 'text-text text-sm' > { ( transformedImageUrl && ! loadingMessage ) ? "Save" : "Recolor" } </ Text >
224
- </ TouchableOpacity >
225
- </ View >
193
+ < ActionButtons
194
+ mainButtonAction = { handleTransformation }
195
+ mainButtonText = { buttonText }
196
+ loading = { loadingMessage ? true : false }
197
+ />
226
198
227
199
</ ScrollView >
228
200
0 commit comments