Skip to content

Commit

Permalink
Fix typo
Browse files Browse the repository at this point in the history
  • Loading branch information
sunnylqm committed Dec 29, 2020
1 parent 10b4578 commit 37a07a7
Show file tree
Hide file tree
Showing 36 changed files with 614 additions and 437 deletions.
2 changes: 1 addition & 1 deletion archived_docs/version-0.44/components-and-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ React Native 提供了一些内置的[核心组件](intro-react-native-component

## Android 独有的组件和 API

下面的组件提供了对 Andriod 常用类的封装。
下面的组件提供了对 Android 常用类的封装。

<div class="component-grid component-grid-border">
<div class="component">
Expand Down
91 changes: 57 additions & 34 deletions archived_docs/version-0.44/listview.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ title: ListView
original_id: listview
---

ListView - 一个核心组件,用于高效地显示一个可以垂直滚动的变化的数据列表。最基本的使用方式就是创建一个`ListView.DataSource`数据源,然后给它传递一个普通的数据数组,再使用数据源来实例化一个`ListView`组件,并且定义它的`renderRow`回调函数,这个函数会接受数组中的每个数据作为参数,返回一个可渲染的组件(作为listview的每一行)。
ListView - 一个核心组件,用于高效地显示一个可以垂直滚动的变化的数据列表。最基本的使用方式就是创建一个`ListView.DataSource`数据源,然后给它传递一个普通的数据数组,再使用数据源来实例化一个`ListView`组件,并且定义它的`renderRow`回调函数,这个函数会接受数组中的每个数据作为参数,返回一个可渲染的组件(作为 listview 的每一行)。

最简单的例子:

Expand All @@ -26,14 +26,15 @@ render() {
}
```

ListView还支持一些高级特性,譬如给每段/组(section)数据添加一个带有粘性的头部(类似iPhone的通讯录,其首字母会在滑动过程中吸附在屏幕上方);在列表头部和尾部增加单独的内容;在到达列表尾部的时候调用回调函数(`onEndReached`),还有在视野内可见的数据变化时调用回调函数(`onChangeVisibleRows`),以及一些性能方面的优化。
ListView 还支持一些高级特性,譬如给每段/组(section)数据添加一个带有粘性的头部(类似 iPhone 的通讯录,其首字母会在滑动过程中吸附在屏幕上方);在列表头部和尾部增加单独的内容;在到达列表尾部的时候调用回调函数(`onEndReached`),还有在视野内可见的数据变化时调用回调函数(`onChangeVisibleRows`),以及一些性能方面的优化。

有一些性能优化使得ListView可以滚动的更加平滑,尤其是在动态加载可能很大(或者概念上无限长的)数据集的时候:
有一些性能优化使得 ListView 可以滚动的更加平滑,尤其是在动态加载可能很大(或者概念上无限长的)数据集的时候:

* 只更新变化的行 - 提供给数据源的rowHasChanged函数可以告诉ListView它是否需要重绘一行数据(即:数据是否发生了变化)参见ListViewDataSource
* 限制频率的行渲染 - 默认情况下,每次消息循环只有一行会被渲染(可以用`pageSize`属性配置)。这把较大的工作分散成小的碎片,以降低因为渲染而导致丢帧的可能性。
- 只更新变化的行 - 提供给数据源的 rowHasChanged 函数可以告诉 ListView 它是否需要重绘一行数据(即:数据是否发生了变化)参见 ListViewDataSource
- 限制频率的行渲染 - 默认情况下,每次消息循环只有一行会被渲染(可以用`pageSize`属性配置)。这把较大的工作分散成小的碎片,以降低因为渲染而导致丢帧的可能性。

### 截图

![](/img/components/listview1.png)

![](/img/components/listview2.png)
Expand Down Expand Up @@ -147,7 +148,7 @@ ListView还支持一些高级特性,譬如给每段/组(section)数据添加
<div class="prop">
<h4 class="propTitle"><a class="anchor" name="stickysectionheadersenabled"></a>stickySectionHeadersEnabled?: <span class="propType">bool</span> <a class="hash-link" href="#stickysectionheadersenabled">#</a></h4>
<div>
<p>设置小节标题(section header)是否具有粘性。粘性是指当它刚出现时,会处在对应小节的内容顶部;继续下滑当它到达屏幕顶端的时候,它会停留在屏幕顶端,一直到对应的位置被下一个小节的标题占据为止。注意此设置在水平模式(<code>horizontal={true}</code>)下无效。由于不同平台的设计原则不同,此选项在iOS上默认开启,andriod上默认关闭。</p>
<p>设置小节标题(section header)是否具有粘性。粘性是指当它刚出现时,会处在对应小节的内容顶部;继续下滑当它到达屏幕顶端的时候,它会停留在屏幕顶端,一直到对应的位置被下一个小节的标题占据为止。注意此设置在水平模式(<code>horizontal={true}</code>)下无效。由于不同平台的设计原则不同,此选项在iOS上默认开启,Android上默认关闭。</p>
</div>
</div>
</div>
Expand All @@ -172,7 +173,6 @@ ListView还支持一些高级特性,譬如给每段/组(section)数据添加
</div>
</div>


### 例子

```jsx
Expand All @@ -187,7 +187,7 @@ var {
StyleSheet,
RecyclerViewBackedScrollView,
Text,
View,
View
} = ReactNative;

var RNTesterPage = require('./RNTesterPage');
Expand All @@ -198,20 +198,22 @@ var ListViewSimpleExample = React.createClass({
description: 'Performant, scrollable list of data.'
},

getInitialState: function() {
var ds = new ListView.DataSource({rowHasChanged: (r1, r2) => r1 !== r2});
getInitialState: function () {
var ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => r1 !== r2
});
return {
dataSource: ds.cloneWithRows(this._genRows({})),
dataSource: ds.cloneWithRows(this._genRows({}))
};
},

_pressData: ({}: {[key: number]: boolean}),
_pressData: ({}: { [key: number]: boolean }),

componentWillMount: function() {
componentWillMount: function () {
this._pressData = {};
},

render: function() {
render: function () {
return (
<RNTesterPage
title={this.props.navigator ? null : '<ListView>'}
Expand All @@ -220,34 +222,46 @@ var ListViewSimpleExample = React.createClass({
<ListView
dataSource={this.state.dataSource}
renderRow={this._renderRow}
renderScrollComponent={props => <RecyclerViewBackedScrollView {...props} />}
renderScrollComponent={(props) => (
<RecyclerViewBackedScrollView {...props} />
)}
renderSeparator={this._renderSeperator}
/>
</RNTesterPage>
);
},

_renderRow: function(rowData: string, sectionID: number, rowID: number, highlightRow: (sectionID: number, rowID: number) => void) {
_renderRow: function (
rowData: string,
sectionID: number,
rowID: number,
highlightRow: (sectionID: number, rowID: number) => void
) {
var rowHash = Math.abs(hashCode(rowData));
var imgSource = THUMB_URLS[rowHash % THUMB_URLS.length];
return (
<TouchableHighlight onPress={() => {
<TouchableHighlight
onPress={() => {
this._pressRow(rowID);
highlightRow(sectionID, rowID);
}}>
<View>
<View style={styles.row}>
<Image style={styles.thumb} source={imgSource} />
<Text style={styles.text}>
{rowData + ' - ' + LOREM_IPSUM.substr(0, rowHash % 301 + 10)}
{rowData +
' - ' +
LOREM_IPSUM.substr(0, (rowHash % 301) + 10)}
</Text>
</View>
</View>
</TouchableHighlight>
);
},

_genRows: function(pressData: {[key: number]: boolean}): Array<string> {
_genRows: function (pressData: {
[key: number]: boolean
}): Array<string> {
var dataBlob = [];
for (var ii = 0; ii < 100; ii++) {
var pressedText = pressData[ii] ? ' (pressed)' : '';
Expand All @@ -256,20 +270,28 @@ var ListViewSimpleExample = React.createClass({
return dataBlob;
},

_pressRow: function(rowID: number) {
_pressRow: function (rowID: number) {
this._pressData[rowID] = !this._pressData[rowID];
this.setState({dataSource: this.state.dataSource.cloneWithRows(
this._genRows(this._pressData)
)});
this.setState({
dataSource: this.state.dataSource.cloneWithRows(
this._genRows(this._pressData)
)
});
},

_renderSeperator: function(sectionID: number, rowID: number, adjacentRowHighlighted: bool) {
_renderSeperator: function (
sectionID: number,
rowID: number,
adjacentRowHighlighted: boolean
) {
return (
<View
key={`${sectionID}-${rowID}`}
style={{
height: adjacentRowHighlighted ? 4 : 1,
backgroundColor: adjacentRowHighlighted ? '#3B5998' : '#CCCCCC',
backgroundColor: adjacentRowHighlighted
? '#3B5998'
: '#CCCCCC'
}}
/>
);
Expand All @@ -288,15 +310,16 @@ var THUMB_URLS = [
require('./Thumbnails/party.png'),
require('./Thumbnails/poke.png'),
require('./Thumbnails/superlike.png'),
require('./Thumbnails/victory.png'),
];
var LOREM_IPSUM = 'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud modus, putant invidunt reprehendunt ne qui.';
require('./Thumbnails/victory.png')
];
var LOREM_IPSUM =
'Lorem ipsum dolor sit amet, ius ad pertinax oportere accommodare, an vix civibus corrumpit referrentur. Te nam case ludus inciderint, te mea facilisi adipiscing. Sea id integre luptatum. In tota sale consequuntur nec. Erat ocurreret mei ei. Eu paulo sapientem vulputate est, vel an accusam intellegam interesset. Nam eu stet pericula reprimique, ea vim illud modus, putant invidunt reprehendunt ne qui.';

/* eslint no-bitwise: 0 */
var hashCode = function(str) {
var hashCode = function (str) {
var hash = 15;
for (var ii = str.length - 1; ii >= 0; ii--) {
hash = ((hash << 5) - hash) + str.charCodeAt(ii);
hash = (hash << 5) - hash + str.charCodeAt(ii);
}
return hash;
};
Expand All @@ -306,15 +329,15 @@ var styles = StyleSheet.create({
flexDirection: 'row',
justifyContent: 'center',
padding: 10,
backgroundColor: '#F6F6F6',
backgroundColor: '#F6F6F6'
},
thumb: {
width: 64,
height: 64,
height: 64
},
text: {
flex: 1,
},
flex: 1
}
});

module.exports = ListViewSimpleExample;
Expand Down
30 changes: 15 additions & 15 deletions archived_docs/version-0.44/vibration.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ original_id: vibration

本模块导出函数`Vibration.vibrate()`用于控制设备震动。震动触发是异步的,也就是说这个函数会立即返回而非等待震动结束。

在不支持震动的设备上(如iOS模拟器),调用此方法没有任何效果。
在不支持震动的设备上(如 iOS 模拟器),调用此方法没有任何效果。

注意对于android来说需要在`AndroidManifest.xml`中添加`<uses-permission android:name="android.permission.VIBRATE"/>`权限。
注意对于 android 来说需要在`AndroidManifest.xml`中添加`<uses-permission android:name="android.permission.VIBRATE"/>`权限。

### 方法

Expand All @@ -17,7 +17,7 @@ original_id: vibration
<h4 class="methodTitle"><a class="anchor" name="vibrate"></a><span class="methodType">static </span>vibrate<span class="methodType">(pattern, repeat)</span> <a class="hash-link" href="#vibrate">#</a>
</h4>
<div>
<p><code>pattern</code>参数为一个不定长的数组。在Andriod上,数组第一个元素表示开始震动前的等待时间,然后是震动持续时长和等待时长的交替,例如[0, 500, 1000, 500]表示立刻开始震动500ms,然后等待1000ms,再震动500ms;但在iOS上震动时长是固定的,所以从数组第二个元素开始都是表示震动的间隔时长。</p>
<p><code>pattern</code>参数为一个不定长的数组。在Android上,数组第一个元素表示开始震动前的等待时间,然后是震动持续时长和等待时长的交替,例如[0, 500, 1000, 500]表示立刻开始震动500ms,然后等待1000ms,再震动500ms;但在iOS上震动时长是固定的,所以从数组第二个元素开始都是表示震动的间隔时长。</p>
<p><code>repeat</code>参数为布尔类型,表示是否持续循环震动。为true时只有调用cancel才会停止。</p>
</div>
</div>
Expand All @@ -30,7 +30,7 @@ original_id: vibration

### 例子

```jsx
```jsx
'use strict';

var React = require('react');
Expand All @@ -41,7 +41,7 @@ var {
Text,
TouchableHighlight,
Vibration,
Platform,
Platform
} = ReactNative;

exports.framework = 'React';
Expand Down Expand Up @@ -78,7 +78,7 @@ exports.examples = [
<Text>{patternDescription}</Text>
</View>
);
},
}
},
{
title: 'Vibration.vibrate()',
Expand All @@ -92,7 +92,7 @@ exports.examples = [
</View>
</TouchableHighlight>
);
},
}
},
{
title: `Vibration.vibrate(${patternLiteral})`,
Expand All @@ -106,7 +106,7 @@ exports.examples = [
</View>
</TouchableHighlight>
);
},
}
},
{
title: `Vibration.vibrate(${patternLiteral}, true)`,
Expand All @@ -120,7 +120,7 @@ exports.examples = [
</View>
</TouchableHighlight>
);
},
}
},
{
title: 'Vibration.cancel()',
Expand All @@ -134,18 +134,18 @@ exports.examples = [
</View>
</TouchableHighlight>
);
},
},
}
}
];

var styles = StyleSheet.create({
wrapper: {
borderRadius: 5,
marginBottom: 5,
marginBottom: 5
},
button: {
backgroundColor: '#eeeeee',
padding: 10,
},
padding: 10
}
});
```
```
2 changes: 1 addition & 1 deletion archived_docs/version-0.45/components-and-apis.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ React Native 提供了一些内置的[核心组件](intro-react-native-component

## Android 独有的组件和 API

下面的组件提供了对 Andriod 常用类的封装。
下面的组件提供了对 Android 常用类的封装。

<div class="component-grid component-grid-border">
<div class="component">
Expand Down
Loading

0 comments on commit 37a07a7

Please sign in to comment.