Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
Former-commit-id: e7c335e
Former-commit-id: 9637d4e
  • Loading branch information
hstarorg committed Mar 20, 2018
1 parent 56477cf commit 7a171a5
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions React Native Cookbook/章节一.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ const icon = playing ? pause : play;

### 更多

在这个配方中,我们使用了 `flexbox` 布局来水平排列播放器控制按钮。如果你想了解更多有关 `Flexbox`的内容,请查看后续 `使用Flexbox创建个人资料页面`。对于更高级的内容,可以阅读第二章实现复杂的用户界面。
在这个配方中,我们使用了 `flexbox` 布局来水平排列播放器控制按钮。如果你想了解更多有关 `Flexbox`的内容,请查看后续 `使用Flexbox创建个人资料页面`。对于更高级的内容,可以阅读第二章实现复杂的用户界面

## 创建一个切换按钮

Expand Down Expand Up @@ -427,13 +427,27 @@ export default MainApp;
```js
import React, { Component } from 'react';
import { AppRegistry } from 'react-nativ
import { AppRegistry } from 'react-native';
import MainApp from './src/MainApp';
AppRegistry.registerComponent('ButtonsAndEvents', () => MainApp);
```
### 原理分析
在步骤 2 中,导入了 `TouchableHighlight` 组件,用来处理触摸事件。
当用户触摸活动区域时,区域内容将通过我们设置的 `underlayColor` 样式高亮显示。
在步骤 3 中,定义了一个有状态组件。在本小节中,`state` 仅仅包含一个属性,但我们可以根据需要添加更多的状态。在第二章“实现复杂的用户界面”中,我们将在更复杂的场景中看到更多的状态处理。
在步骤 6 中,使用 `setState` 来更新 `liked` 属性的值。这个方法正是从 `Component` 类中继承而来。
在步骤 7 中,根据当前 `state``liked` 属性来设置图片颜色为红色,通过返回 `null` 来避免应用任何样式。使用数组来组合多个对象样式对于应用样式非常方便,在内部,组件会将所有样式合并为一个对象。后定义的属性将会覆盖先定义的同名属性。
### 更多
在一个真实的 App 中,我们将可能使用多种按钮,图标左对齐,带标签,不同的尺寸和颜色等等。此时,强烈建议您创建可复用的组件,以避免在 App 中到处重复代码。在第二章“实现复杂的用户界面”中,我们将创建一个按钮来组件来处理其中的一些场景。
## 显示列表元素
## 在视窗中添加选项卡
Expand Down

0 comments on commit 7a171a5

Please sign in to comment.