zhouzhongyuan / qa

Questions recods
MIT License
5 stars 1 forks source link

What is react-navigation? #51

Open zhouzhongyuan opened 7 years ago

zhouzhongyuan commented 7 years ago
zhouzhongyuan commented 7 years ago

Resolved

How does StackNavigator work?

What determines the height of TabNavigator's tabBar?

zhouzhongyuan commented 7 years ago

文中代码

入口文件: src/react-navigation.js

module.exports = {
  // Core
  get createNavigationContainer() {
    return require('./createNavigationContainer').default;
  },
}

这种写法的作用:有时候希望访问属性时能返回一个动态计算后的值, 或希望不通过使用明确的方法调用而显示内部变量的状态。

简单的解释代码

代码1:

var person ={
    name: "zhongyuan",
}

代码2:

var person = {
    get name(){
        return "zhongyuan";
    }
}

在取person.name值的时候,效果是一样。 参考getter MDN

zhouzhongyuan commented 7 years ago

探究

收获

1. 最简单的StackNavigator是如何渲染的?

What is navigator?

What is router?

用到了哪几个 api ?

2. StackNavigator如何进行切换?

2.1 如何进入?

this.props.navigation.navigate('chat')做了什么?

2.1.1 this.props.navigation.navigate从哪儿来的?

应该首先看

Answer:

navigate in react-navigation/src/addNavigationHelpers.js

addNavigationHelpers in react-navigation/src/createNavigationContainer.js  

Answer:

navigate
dispatch
setState

2.2 如何返回?

2.3 router的历史信息记录在哪里?

It saves at StackRouter.js.

zhouzhongyuan commented 7 years ago

How does StackNavigator work?

The simplest usage of StackNavigator is like below:

Code: ``` class HomeScreen extends React.Component { static navigationOptions = { title: 'Welcome', }; render() { return Hello, Navigation!; } } const SimpleApp = StackNavigator({ Home: { screen: HomeScreen }, }); ```

渲染示意图 react-navigation - page 1

zhouzhongyuan commented 7 years ago

How does cardStyle work?

zhouzhongyuan commented 6 years ago

What determines the height of TabNavigator's tabBar?

Simple code ```javascript class RecentChatsScreen extends React.Component { render() { return List of recent chats } } class AllContactsScreen extends React.Component { render() { return List of all contacts } } const MainScreenNavigator = TabNavigator({ Recent: {screen: RecentChatsScreen}, All: {screen: AllContactsScreen}, }, { tabBarPosition: 'bottom', }); ```
Style

What determines the height of TabNavigator's tabBar ? aka, the height of blue area in "Style" picture.

react-navigation-tabbar-height

总计50px。

Answer: font-size(Text), margin(Text), padding(View)

zhouzhongyuan commented 6 years ago

How does goBack work?

navigation includes: index key routeName routes