44 */
55
66import React , { Component } from 'react' ;
7- import {
8- StyleSheet ,
9- ImageBackground ,
10- DeviceEventEmitter
11- } from 'react-native' ;
7+ import { StyleSheet , ImageBackground , DeviceEventEmitter } from 'react-native' ;
128
139import { ShiTuMobx } from '../../mobx/ShiTu' ;
1410
@@ -33,87 +29,80 @@ type Props = {
3329 configStore : ConfigStore
3430} ;
3531
36- type State = {
37- aaa : string
38- } ;
39-
40- @inject ( 'configStore' , 'powerStore' )
41- @observer
42- class ShiTu extends Component < Props , State > {
43- shiTuMobx : ShiTuMobx ;
32+ const shiTuMobx : ShiTuMobx = new ShiTuMobx ( ) ;
33+ ActionSheet . ActionSheetView . Item = PopoverActionSheetItem ;
4434
45- constructor ( props : Props ) {
46- super ( props ) ;
47- ActionSheet . ActionSheetView . Item = PopoverActionSheetItem ;
48- this . shiTuMobx = new ShiTuMobx ( ) ;
49- }
35+ function selectedImagePicker ( type : string , callBack : Function ) {
36+ ActionSheet . hide ( ) ;
5037
51- componentDidMount ( ) {
52- DeviceEventEmitter . emit ( 'badgeNumber' , 20 ) ;
53- }
54-
55- selectedImagePicker = ( type : string ) = > {
38+ const options = {
39+ quality : 0.5 ,
40+ allowsEditing : false ,
41+ noData : true ,
42+ storageOptions : {
43+ skipBackup : true ,
44+ path : 'ShiTu'
45+ }
46+ } ;
5647
57- ActionSheet . hide ( ) ;
48+ const launchType = `launch ${ type } ` ;
5849
59- const options = {
60- quality : 0.5 ,
61- allowsEditing : false ,
62- noData : true ,
63- storageOptions : {
64- skipBackup : true ,
65- path : 'ShiTu'
66- }
67- } ;
50+ ImagePicker [ launchType ] ( options , imageResponse => {
51+ // console.log('options', options, imageResponse);
6852
69- const launchType = `launch ${ type } ` ;
53+ if ( imageResponse . didCancel ) return ;
7054
71- ImagePicker [ launchType ] ( options , async imageResponse => {
55+ callBack ( imageResponse ) ;
56+ } ) ;
57+ }
7258
73- console . log ( 'options' , options , imageResponse ) ;
59+ function openImagePicker ( imageResponse ) {
60+ const items = [
61+ {
62+ title : '拍照' ,
63+ onPress : ( ) => selectedImagePicker ( 'Camera' , imageResponse )
64+ } ,
65+ {
66+ title : '选择相册' ,
67+ onPress : ( ) => selectedImagePicker ( 'ImageLibrary' , imageResponse )
68+ }
69+ ] ;
70+ const cancelItem = { title : '取消' } ;
71+ ActionSheet . show ( items , cancelItem ) ;
72+ }
7473
75- if ( imageResponse . didCancel ) return ;
74+ const ShiTu = inject ( 'configStore' , 'powerStore' ) (
75+ observer ( function ( props : Props ) {
76+ const { ShiTuBackgroundImage } = props . powerStore ;
77+ const { showLoading, hideLoading } = props . configStore ;
78+ const { uploadImage, getSearchDetail } = shiTuMobx ;
7679
77- this . props . configStore . showLoading ( ) ;
80+ function openImagePickerAndHandleImageData ( ) {
81+ openImagePicker ( async imageResponse => {
82+ showLoading ( ) ;
7883
79- const imageData = await this . shiTuMobx . uploadImage ( imageResponse ) ;
84+ const imageData = await uploadImage ( imageResponse ) ;
8085
81- const params = {
82- token : imageData . key
83- } ;
86+ const params = {
87+ token : imageData . key
88+ } ;
8489
85- const searchDetail = await this . shiTuMobx . getSearchDetail ( params ) ;
90+ const searchDetail = await getSearchDetail ( params ) ;
8691
87- this . props . configStore . hideLoading ( ) ;
92+ hideLoading ( ) ;
8893
89- this . props . navigation . navigate ( 'WebView' , {
90- uri : searchDetail . data . webURL
94+ props . navigation . navigate ( 'WebView' , {
95+ uri : searchDetail . data . webURL
96+ } ) ;
9197 } ) ;
92- } ) ;
93- } ;
98+ }
9499
95- openImagePicker = async ( ) => {
96- const items = [
97- {
98- title : '拍照' ,
99- onPress : ( ) => this . selectedImagePicker ( 'Camera' )
100- } ,
101- {
102- title : '选择相册' ,
103- onPress : ( ) => this . selectedImagePicker ( 'ImageLibrary' )
104- }
105- ] ;
106- const cancelItem = { title : '取消' } ;
107- ActionSheet . show ( items , cancelItem ) ;
108- } ;
109-
110- render ( ) {
111100 return (
112101 < BaseContainer title = { '识兔' } isTopNavigator = { true } >
113102 < AnimationImageBackground
114103 style = { styles . container }
115104 animation = "fadeIn"
116- source = { { uri : this . props . powerStore . ShiTuBackgroundImage } }
105+ source = { { uri : ShiTuBackgroundImage } }
117106 blurRadius = { System . Android ? 5 : 5 }
118107 >
119108 < AnimationButton
@@ -122,14 +111,14 @@ class ShiTu extends Component<Props, State> {
122111 useNativeDriver
123112 titleStyle = { styles . buttonTitle }
124113 gradientStyle = { styles . button }
125- onPress = { this . openImagePicker }
114+ onPress = { openImagePickerAndHandleImageData }
126115 btnStyle = { styles . btnStyle }
127116 />
128117 </ AnimationImageBackground >
129118 </ BaseContainer >
130119 ) ;
131- }
132- }
120+ } )
121+ ) ;
133122
134123const styles = StyleSheet . create ( {
135124 container : {
0 commit comments