Jane book article react-native-easy-app Detailed and use
const url = ' https://www.baidu.com ' ;
* 同步请求
const response = await XHttp().url(url).execute('GET');
const {success, json, message, status} = response;
if(success){
this.setState({content: JSON.stringify(json)})
} else {
showToast(message)
}
* 异步请求
XHttp().url(url).get((success, json, message, status)=>{
if (success){
this.setState({content: JSON.stringify(json)});
} else {
showToast(msg);
}
});
* 异步请求
XHttp().url(url).execute('GET')
.then(({success, json, message, status}) => {
if (success) {
this.setState({content: JSON.stringify(json)});
} else {
showToast(message);
}
})
.catch(({message}) => {
showToast(message);
})
* Custom AsyncStorage instance object
const RNStorage = {
customerId : undefined ,
hasLogin : undefined ,
userInfo : {}
}
* Associate the instance object RNStorage with the AsyncStorage storage data
XStorage . initStorage ( RNStorage , () => (), ' 1.0 ' )
* Assuming that userInfo = () information
can be returned after logging in XHttp () . Url ( Api . AuthCodeLogin ) . Param ( params ) . Post (( success , json , msg , code ) => {
if ( success ) {
RNStorage . HasLogin = true ; // bool type storage
RNStorage . customerId = String (JSON . ID ); // string type storage
RNStorage . the userInfo = JSON . the userInfo ; // object type stored
Navigation . Replace ( ' the Main ' );
} else {
showToast(msg);
}
});
* Can be used directly for other applications where a RNStorage access memory through the data
IF ( RNStorage . HasLogin ) {
the let { name , Age , idCard } = RNStorage . The userInfo ;
Console . Log ( name , Age , idCard , RNStorage . The customerId ); // Print user information
}
* XText Text form code with icon is as follows
< XText style = { styles . GrayText } text = ' Text display ' />
< XText style = { styles . Text } onPress = { () => showToast ( ' click event ' ) } text = ' Text display (with touch effect) ' />
<XView style={styles.iconTextParent}>
<XText style={styles.iconText} text='文本' icon='mine_focus_shop' iconSize={20} position='left'/>
<XText style={styles.iconText} text='文本' icon='mine_focus_shop' iconSize={20} position='right'/>
<XText style={styles.iconText} text='文本' icon='mine_focus_shop' iconSize={20} position='top'/>
< XText style = { styles . IconText } text = ' clickable ' icon = ' mine_focus_shop ' iconSize = { 20 } position = ' bottom ' onPress = { () => showToast ( ' click event ' ) } />
< XText style = { styles . IconText } text = ' No icon ' />
</XView>
<XText style={styles.rnTextItem} text='订单' icon='item_arrow_right' iconSize={16} position='right' textExtend={true}/>
<XView style={{backgroundColor: Colors.white, marginBottom: 30}}>
< XText style = { styles . RnSearch } text = ' Please enter customer name... ' icon = ' home_search_icon ' iconSize = { 16 } position = ' left ' iconMargin = { 6 } onPress = { () => showToast ( ' Click Jump to search ' ) } />
</XView>
* XImage image attribute setting source code is as follows
<XView style={{flexDirection: 'row', justifyContent: 'space-between', marginBottom: 30}}>
<XImage style={{width: 65, height: 65}} icon='login_logo'/>
<XImage style={{width: 65, height: 65}} icon={imgUrl}/>
<XImage style={styles.rnImage} icon={imgUrl} onPress={() => showToast('柯南')}/>
<XImage style={{width: 65, height: 65}} icon='mine_setting' onPress={() => showToast('点击事件')}/>
<XImage style={{width: 65, height: 65}} icon='mine_setting' onPress={() => showToast('点击事件')} iconSize={30}/>
</XView>
<XFlatList data={dataList}
onRefresh={() => this.queryDataList(true)}
onLoadMore={() => this.queryDataList(false)}
ListHeaderComponent={() => <RNText style={styles.header} text={headerText}/>}
ref={refreshList => this.refreshList = refreshList}
renderItem={({item, index}) => <CarItem onItemSelected={(model) => showToast(model.title)}/>}/>
this.refreshList.refreshPreLoad(isPullDown)
this.refreshList.refreshLoaded(success, isPullDown, reachedEnd, code)
please refer to the example project for specific usage * Source code implementation
export function resetStyle ( style ) { // Reset properties (ignore outer size)
let styles = { ... flattenStyle ( selfOr ( style , ()))};
Object . Keys ( styles ) . ForEach (( keyStr ) => {
if ( Props . sizeProps . has ( keyStr )) { //The size attribute needs to be modified
if ( keyStr === 'fontSize') {//字体属性
styles[keyStr] = RTSize(styles[keyStr]);
} else {
let value = styles [ keyStr ]; // Style attribute value, if it is integer data and not onePixel, reset the value
if ( typeof value === ' number ' && value !== Const . onePixel ) {
styles [ keyStr ] = RNSize ( value );
}
}
}
});
return styles;
}
Author: chende008
Source Code: https://github.com/chende008/react-native-easy-app-sample
#react-native #react #mobile-apps