react-native-scrollable-tab-view
goBack()
全局脚手架
npm i -g react-native-cli
安装基础项目
react-native init <项目名称>
优化后的运行
npm run ios
npm run android
npm run s
原始启动
react-native run-ios
react-native run-android
365个库中寻找77个
complete.js
中添加数据,方便在完成的探索
中出现AppStackNavigators.js
里面进行引入=>注册
,使得路由正常scripts
中添加,如下内容:"ios":"react-native run-ios",
"android":"react-native run-android",
"s":"npm run ios && npm run android",
flex:1
进行优化display: 'flex';
flexDirection: row | row-reverse | column | column-reverse;
flexWrap: nowrap | wrap | wrap-reverse;
flexFlow: <flex-direction> || <flex-wrap>;
justifyContent: flex-start | flex-end | center | space-between | space-around;
alignItems: flex-start | flex-end | center | baseline | stretch;
alignContent: flex-start | flex-end | center | space-between | space-around | stretch;
order: <integer>;
flexGrow: <number>; /* default 0 */
flexShrink: <number>; /* default 1 */
flexBasis: <length> | auto; /* default auto */
flex: none | [ <'flex-grow'> <'flex-shrink'>? || <'flex-basis'> ]
alignSelf: auto | flex-start | flex-end | center | baseline | stretch;
图片使用
<Image source={require('./my-icon.png')} />
命名规则
icon_test.png
icon_test@2x.png
icon_test@3x.png
第一步
安装带原生依赖的库
npm install <某个带有原生依赖的库> --save
第二步
运行以下命令,它会根据
package.json
文件中的dependencies
和devDependencies
记录来链接所有需要链接的库
react-native link
使用"Touchable"开头的一系列组件
通过onPress属性接受一个点击事件的处理函数
_onPressButton=((item)=>{
alert(1)
console.log(item);
})
render() {
return (
<View>
<TouchableHighlight onPress={this._onPressButton}>
<View style={[S.btn,{backgroundColor:`${this.state.bg}`}]}>
<Text style={S.btnText}>{this.state.bg}</Text>
</View>
</TouchableHighlight>
<TouchableHighlight onPress={()=>{
this._onPressButton(this.state.bg)
}}>
<View style={[S.btn,{backgroundColor:`${this.state.bg}`}]}>
<Text style={S.btnText}>{this.state.bg}</Text>
</View>
</TouchableHighlight>
</View>
);
}
js版本和rn版本出现冲突
watchman watch-del-all
react-native start --reset-cache
createTabNavigator
要在createStackNavigator
里面进行注册,才能够使用createStackNavigator
具有的方法,这个是我第二次配置的时候掉进的一个坑this.props.navigation属性详细说明
createTabNavigator
里面没有push
、replace
等方法createStackNavigator
中存在push
、replace
等方法
JSON value '<null>' of type NSNull
undefined
的时候,报错this.state
中保存初始值为空,必要时可以提醒用户Valid style props: [
"alignContent",
"alignItems",
"alignSelf",
"aspectRatio",
"backfaceVisibility",
"backgroundColor",
"borderBottomColor",
"borderBottomEndRadius",
"borderBottomLeftRadius",
"borderBottomRightRadius",
"borderBottomStartRadius",
"borderBottomWidth",
"borderColor",
"borderEndColor",
"borderEndWidth",
"borderLeftColor",
"borderLeftWidth",
"borderRadius",
"borderRightColor",
"borderRightWidth",
"borderStartColor",
"borderStartWidth",
"borderStyle",
"borderTopColor",
"borderTopEndRadius",
"borderTopLeftRadius",
"borderTopRightRadius",
"borderTopStartRadius",
"borderTopWidth",
"borderWidth",
"bottom",
"color",
"decomposedMatrix",
"direction",
"display",
"elevation",
"end",
"flex",
"flexBasis",
"flexDirection",
"flexGrow",
"flexShrink",
"flexWrap",
"fontFamily",
"fontSize",
"fontStyle",
"fontVariant",
"fontWeight",
"height",
"includeFontPadding",
"justifyContent",
"left",
"letterSpacing",
"lineHeight",
"margin",
"marginBottom",
"marginEnd",
"marginHorizontal",
"marginLeft",
"marginRight",
"marginStart",
"marginTop",
"marginVertical",
"maxHeight",
"maxWidth",
"minHeight",
"minWidth",
"opacity",
"overflow",
"overlayColor",
"padding",
"paddingBottom",
"paddingEnd",
"paddingHorizontal",
"paddingLeft",
"paddingRight",
"paddingStart",
"paddingTop",
"paddingVertical",
"position",
"resizeMode",
"right",
"rotation",
"scaleX",
"scaleY",
"shadowColor",
"shadowOffset",
"shadowOpacity",
"shadowRadius",
"start",
"textAlign",
"textAlignVertical",
"textDecorationColor",
"textDecorationLine",
"textDecorationStyle",
"textShadowColor",
"textShadowOffset",
"textShadowRadius",
"textTransform",
"tintColor",
"top",
"transform",
"transformMatrix",
"translateX",
"translateY",
"width",
"writingDirection",
"zIndex"
]
设置StatusBar
<StatusBar
backgroundColor="transparent"
translucent
/>
设置顶部模块的样式
height: 50,
paddingTop: 10,
三种方法实现跨平台:
Platform.OS
Platform
的select
方法header.ios.js
;android使用header.android.js
const instructions = Platform.select({
ios: 'ios',
android: 'android',
});
HttpUtils.js
引入
import HttpUtils from '../../HttpUtils';
使用
global.data.domain
保存请求域名,global.data.token
HttpUtils.post(`${apiConfig}`, {
platform: 'ios'
},global.data.token)
.then(rtn => {
global.data.config = rtn;
// console.log(`配置=>( ${JSON.stringify(rtn)} )`);
})
.catch(err => {
console.log('error', err)
})
请求环境
addr.js
中env
变量定义请求地址
addr.js
中addrList
统一管理所有请求地址使用
import addrList from '../../addr';
const {apiConfig}=addrList;
react-native-scrollable-tab-view
~/node_modules/react-native-scrollable-tab-viewSceneComponent.js
下删除即可npm config set registry https://registry.npm.taobao.org
npm config set disturl https://npm.taobao.org/dist
goBack()
componentDidMount(){}
goBack()
需要重新加载app
第一步
goBack
事件componentWillUnmount(){
DeviceEventEmitter.emit('goBack', 'goBack刷新返回页面数据');
}
第二步
goBack
自定义事件componentDidMount(){
// 接收
this.deEmitter = DeviceEventEmitter.addListener('goBack', (a) => {
this.loadData();
});
}
android/app
目录下~/.gradle/gradle.properties
或../android/gradle.properties
(一个是全局gradle.properties
,一个是项目中的gradle.properties
,大家可以根据需要进行修改) ,加入如下代码:MYAPP_RELEASE_STORE_FILE=ch09-keystore.jks
MYAPP_RELEASE_KEY_ALIAS=ch09-keystore
MYAPP_RELEASE_STORE_PASSWORD=123456
MYAPP_RELEASE_KEY_PASSWORD=123456
android/app/build.gradle
文件添加如下代码:...
android {
...
defaultConfig { ... }
signingConfigs {
release {
storeFile file(MYAPP_RELEASE_STORE_FILE)
storePassword MYAPP_RELEASE_STORE_PASSWORD
keyAlias MYAPP_RELEASE_KEY_ALIAS
keyPassword MYAPP_RELEASE_KEY_PASSWORD
}
}
buildTypes {
release {
...
signingConfig signingConfigs.release
}
}
}
...
./gradlew assembleRelease
android/app/build/outputs/apk/
目录下看到签名成功后的app-release.apk
文件。/**
* Run Proguard to shrink the Java bytecode in release builds.
*/
def enableProguardInReleaseBuilds = true
fetch(apiLogin, {
method: 'POST',
headers: {
'Accept': 'application/json',//通过头指定,获取的数据类型是JSON
'Content-Type': 'application/json',
'Authorization':global.data.token,
},
body: JSON.stringify({
// 请求参数
})
})
.then(result => {
const {status,statusText} = result;
if(status>=200&&status<300||status==304){
// 成功
const promise = result.json()
promise.then(rtn=>{
// 成功
})
}else if(status==403){
// 跳转登录
this.props.navigation.replace('login');
}else{
// 提醒 statusText
this.refs.toast.show(statusText);
}
})
.catch(error => {
if(Object.prototype.toString.call(error) === '[object Object]'){
this.refs.toast.show(JSON.stringify(error))
}else{
this.refs.toast.show(error)
}
})
LOGO
android/app/src/main/res
下的四个文件夹中,命名为ic_launcher.png
1024*1024
或者512*512
的即可app名称
android/app/src/main/res/values/strings.xml
中更改LOGO
xcode>
根目录 >Images.xcassets
将生成的图标拖入对应的位置app名称
xcode>
根目录 >Info.plist
中修改 Bundlename
和 General> DIsplay Name