@@ -2,16 +2,21 @@ import { Buffer } from 'buffer';
2
2
import React , { useState , useEffect , useContext } from 'react' ;
3
3
4
4
import { bytesToHex } from '@noble/hashes/utils' ;
5
- import { Picker } from '@react-native-picker/picker' ;
6
5
import * as ImagePicker from 'expo-image-picker' ;
7
6
import { Action , manipulateAsync , SaveFormat } from 'expo-image-manipulator' ;
8
7
9
8
import { DeviceUploadResourceParams , getHomeScreenSize , getDeviceType } from '@onekeyfe/hd-core' ;
10
9
import { ResourceType } from '@onekeyfe/hd-transport' ;
11
- import { Image , Label , Stack , View , XStack } from 'tamagui' ;
10
+ import { Image as ImageView , Label , Stack , View , XStack } from 'tamagui' ;
12
11
import { Platform } from 'react-native' ;
13
12
import { useIntl } from 'react-intl' ;
14
- import { getImageSize , imageToBase64 , formatBytes , generateUploadNFTParams } from './nftUtils' ;
13
+ import {
14
+ getImageSize ,
15
+ imageToBase64 ,
16
+ formatBytes ,
17
+ generateUploadNFTParams ,
18
+ processImageBlur ,
19
+ } from './nftUtils' ;
15
20
import HardwareSDKContext from '../../provider/HardwareSDKContext' ;
16
21
import { useCommonParams } from '../../provider/CommonParamsProvider' ;
17
22
import { useDevice } from '../../provider/DeviceProvider' ;
@@ -24,6 +29,8 @@ interface UploadResourceParams {
24
29
resType ?: number ;
25
30
nftMetaData ?: string ;
26
31
fileNameNoExt ?: string ;
32
+ blurRadius ?: number ;
33
+ blurOverlayOpacity ?: number ;
27
34
}
28
35
29
36
function getUrlExtension ( url : string ) {
@@ -39,6 +46,8 @@ export const generateUploadResParams = async ({
39
46
height,
40
47
homeScreenSize,
41
48
homeScreenThumbnailSize,
49
+ blurRadius,
50
+ blurOverlayOpacity,
42
51
cb,
43
52
} : {
44
53
uri : string ;
@@ -52,6 +61,8 @@ export const generateUploadResParams = async ({
52
61
width : number ;
53
62
height : number ;
54
63
} ;
64
+ blurRadius ?: number ;
65
+ blurOverlayOpacity ?: number ;
55
66
cb ?: ( data : { base64 ?: string } ) => void ;
56
67
} ) => {
57
68
const data = await compressHomescreen (
@@ -69,6 +80,12 @@ export const generateUploadResParams = async ({
69
80
height
70
81
) ;
71
82
83
+ const blurData = await processImageBlur ( {
84
+ base64Data : data ?. base64 ?? '' ,
85
+ blurRadius : blurRadius ?? 100 ,
86
+ overlayOpacity : blurOverlayOpacity ?? 0.2 ,
87
+ } ) ;
88
+
72
89
cb ?.( data as any ) ;
73
90
74
91
if ( ! data ?. arrayBuffer && ! zoomData ?. arrayBuffer ) return ;
@@ -84,6 +101,7 @@ export const generateUploadResParams = async ({
84
101
suffix : 'jpeg' ,
85
102
dataHex : bytesToHex ( data ?. arrayBuffer as Uint8Array ) ,
86
103
thumbnailDataHex : bytesToHex ( zoomData ?. arrayBuffer as Uint8Array ) ,
104
+ blurDataHex : blurData . hex ,
87
105
nftMetaData : '' ,
88
106
fileNameNoExt : undefined ,
89
107
} ;
@@ -214,6 +232,8 @@ function UploadScreenComponent() {
214
232
height,
215
233
homeScreenSize : HomeScreenSize ,
216
234
homeScreenThumbnailSize : HomeScreenThumbnailSize ,
235
+ blurRadius : uploadScreenParams ?. blurRadius ?? 100 ,
236
+ blurOverlayOpacity : uploadScreenParams ?. blurOverlayOpacity ?? 0.2 ,
217
237
cb : data => {
218
238
setImage ( { uri : base64 } as any ) ;
219
239
setPreviewData ( data ?. base64 ? `data:image/png;base64,${ data . base64 } ` : null ) ;
@@ -275,6 +295,8 @@ function UploadScreenComponent() {
275
295
height : image . height ?? 0 ,
276
296
homeScreenSize : HomeScreenSize ,
277
297
homeScreenThumbnailSize : HomeScreenThumbnailSize ,
298
+ blurRadius : uploadScreenParams ?. blurRadius ?? 100 ,
299
+ blurOverlayOpacity : uploadScreenParams ?. blurOverlayOpacity ?? 0.2 ,
278
300
cb : data => {
279
301
setPreviewData ( data ?. base64 ? `data:image/png;base64,${ data . base64 } ` : null ) ;
280
302
} ,
@@ -386,6 +408,40 @@ function UploadScreenComponent() {
386
408
}
387
409
} }
388
410
/>
411
+ < CommonInput
412
+ type = "number"
413
+ label = "Blur Radius"
414
+ value = { uploadScreenParams ?. blurRadius ?. toString ( ) ?? '100' }
415
+ placeholder = "100"
416
+ onChange = { v => {
417
+ if ( ! isInputDisabled ) {
418
+ try {
419
+ parseInt ( v ) ;
420
+ } catch ( e ) {
421
+ alert ( 'Blur Radius must be a number' ) ;
422
+ return ;
423
+ }
424
+ setUploadScreenParams ( { ...uploadScreenParams , blurRadius : parseInt ( v ) } ) ;
425
+ }
426
+ } }
427
+ />
428
+ < CommonInput
429
+ type = "number"
430
+ label = "Blur Overlay Opacity"
431
+ value = { uploadScreenParams ?. blurOverlayOpacity ?. toString ( ) ?? '0.2' }
432
+ placeholder = "100"
433
+ onChange = { v => {
434
+ if ( ! isInputDisabled ) {
435
+ try {
436
+ parseInt ( v ) ;
437
+ } catch ( e ) {
438
+ alert ( 'Blur Overlay Opacity must be a number' ) ;
439
+ return ;
440
+ }
441
+ setUploadScreenParams ( { ...uploadScreenParams , blurOverlayOpacity : parseInt ( v ) } ) ;
442
+ }
443
+ } }
444
+ />
389
445
< Button onPress = { ( ) => handleScreenUpdate ( 'WallPaper' ) } disabled = { isLoading || ! image } >
390
446
{ isLoading ? 'Uploading...' : intl . formatMessage ( { id : 'action__upload' } ) }
391
447
</ Button >
@@ -421,6 +477,40 @@ function UploadScreenComponent() {
421
477
}
422
478
} }
423
479
/>
480
+ < CommonInput
481
+ type = "number"
482
+ label = "Blur Radius"
483
+ value = { uploadScreenParams ?. blurRadius ?. toString ( ) ?? '100' }
484
+ placeholder = "100"
485
+ onChange = { v => {
486
+ if ( ! isInputDisabled ) {
487
+ try {
488
+ parseInt ( v ) ;
489
+ } catch ( e ) {
490
+ alert ( 'Blur Radius must be a number' ) ;
491
+ return ;
492
+ }
493
+ setUploadScreenParams ( { ...uploadScreenParams , blurRadius : parseInt ( v ) } ) ;
494
+ }
495
+ } }
496
+ />
497
+ < CommonInput
498
+ type = "number"
499
+ label = "Blur Overlay Opacity"
500
+ value = { uploadScreenParams ?. blurOverlayOpacity ?. toString ( ) ?? '0.2' }
501
+ placeholder = "100"
502
+ onChange = { v => {
503
+ if ( ! isInputDisabled ) {
504
+ try {
505
+ parseInt ( v ) ;
506
+ } catch ( e ) {
507
+ alert ( 'Blur Overlay Opacity must be a number' ) ;
508
+ return ;
509
+ }
510
+ setUploadScreenParams ( { ...uploadScreenParams , blurOverlayOpacity : parseInt ( v ) } ) ;
511
+ }
512
+ } }
513
+ />
424
514
< Button onPress = { loadNftData } disabled = { isLoading || ! nftUrl } marginRight = "$2" >
425
515
{ isLoading ? 'Loading...' : 'Load NFT Data' }
426
516
</ Button >
@@ -434,7 +524,7 @@ function UploadScreenComponent() {
434
524
预览
435
525
</ Label >
436
526
{ image && (
437
- < Image
527
+ < ImageView
438
528
height = { 800 }
439
529
width = { 480 }
440
530
source = { { uri : image . uri } }
@@ -444,7 +534,7 @@ function UploadScreenComponent() {
444
534
) }
445
535
{ previewData && (
446
536
// NFT
447
- < Image height = { 238 } width = { 238 } source = { { uri : previewData } } />
537
+ < ImageView height = { 238 } width = { 238 } source = { { uri : previewData } } />
448
538
// HOME SCREEN
449
539
// <Image style={{ height: 800, width: 480 }} source={{ uri: previewData }} />
450
540
) }
0 commit comments