Skip to content

Commit 94f4926

Browse files
committed
fixed #16 close #16
1 parent 80241cd commit 94f4926

File tree

5 files changed

+334
-39
lines changed

5 files changed

+334
-39
lines changed

MJFlatList.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import React, {Component} from 'react';
2+
import {VirtualizedList, FlatList,Platform} from 'react-native';
3+
import MJMetroListView from './MJMetroListView'
4+
5+
class MJFlatList extends FlatList {
6+
render() {
7+
if (this.props.legacyImplementation) {
8+
return (
9+
<MJMetroListView
10+
{...this.props}
11+
items={this.props.data}
12+
ref={this._captureRef}
13+
/>
14+
);
15+
} else {
16+
return (
17+
<VirtualizedList
18+
{...this.props}
19+
renderItem={this._renderItem}
20+
getItem={this._getItem}
21+
getItemCount={this._getItemCount}
22+
keyExtractor={this._keyExtractor}
23+
ref={this._captureRef}
24+
onViewableItemsChanged={
25+
this.props.onViewableItemsChanged && this._onViewableItemsChanged
26+
}
27+
/>
28+
);
29+
}
30+
}
31+
}
32+
33+
module.exports = Platform.OS === 'ios' ? MJFlatList : FlatList;

MJListView.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,40 @@
1+
import React,{Component} from 'react';
12
import {
2-
findNodeHandle,
3-
NativeModules,
4-
} from 'react-native'
3+
findNodeHandle,
4+
NativeModules,
5+
Platform,
6+
ListView,
7+
} from 'react-native';
8+
import MJScrollView from './MJScrollView'
9+
const RCTMJScrollViewManager = NativeModules.MJScrollViewManager;
10+
var DEFAULT_PAGE_SIZE = 1;
11+
var DEFAULT_INITIAL_ROWS = 10;
12+
var DEFAULT_SCROLL_RENDER_AHEAD = 1000;
13+
var DEFAULT_END_REACHED_THRESHOLD = 1000;
514

6-
const ListView = require('react-native/Libraries/Lists/ListView/ListView')
7-
8-
const RCTMJScrollViewManager = NativeModules.MJScrollViewManager
9-
10-
module.exports = class MJListView extends ListView {
11-
_measureAndUpdateScrollProps = () => {
12-
var scrollComponent = this.getScrollResponder();
13-
if (!scrollComponent || !scrollComponent.getInnerViewNode) {
14-
return;
15+
class MJListView extends ListView {
16+
static defaultProps = {
17+
initialListSize: DEFAULT_INITIAL_ROWS,
18+
pageSize: DEFAULT_PAGE_SIZE,
19+
renderScrollComponent: props => <MJScrollView {...props} />,
20+
scrollRenderAheadDistance: DEFAULT_SCROLL_RENDER_AHEAD,
21+
onEndReachedThreshold: DEFAULT_END_REACHED_THRESHOLD,
22+
stickySectionHeadersEnabled: Platform.OS === 'ios',
23+
stickyHeaderIndices: [],
1524
}
1625

17-
RCTMJScrollViewManager &&
18-
RCTMJScrollViewManager.calculateChildFrames &&
19-
RCTMJScrollViewManager.calculateChildFrames(
20-
findNodeHandle(scrollComponent),
21-
this._updateVisibleRows,
22-
)
23-
}
26+
_measureAndUpdateScrollProps = () => {
27+
var scrollComponent = this.getScrollResponder();
28+
if (!scrollComponent || !scrollComponent.getInnerViewNode) {
29+
return;
30+
}
31+
RCTMJScrollViewManager &&
32+
RCTMJScrollViewManager.calculateChildFrames &&
33+
RCTMJScrollViewManager.calculateChildFrames(
34+
findNodeHandle(scrollComponent),
35+
this._updateVisibleRows,
36+
)
37+
}
2438
}
39+
40+
module.exports = Platform.OS === 'ios' ? MJListView : ListView;

MJMetroListView.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import React, {Component} from 'react';
2+
import {RefreshControl} from 'react-native';
3+
4+
const MetroList = require('react-native/Libraries/Lists/MetroListView')
5+
const MJListView = require('./MJListView');
6+
const MJScrollView = require('./MJScrollView');
7+
8+
export default class MJMetroListView extends MetroList {
9+
static defaultProps = {
10+
keyExtractor: (item, index) => item.key || String(index),
11+
renderScrollComponent: (props) => {
12+
if (props.onRefresh) {
13+
return (
14+
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
15+
* comment suppresses an error when upgrading Flow's support for
16+
* React. To see the error delete this comment and run Flow. */
17+
<MJScrollView
18+
{...props}
19+
refreshControl={
20+
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss)
21+
* This comment suppresses an error when upgrading Flow's support
22+
* for React. To see the error delete this comment and run Flow.
23+
*/
24+
<RefreshControl
25+
refreshing={props.refreshing}
26+
onRefresh={props.onRefresh}
27+
/>
28+
}
29+
/>
30+
);
31+
} else {
32+
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
33+
* comment suppresses an error when upgrading Flow's support for React.
34+
* To see the error delete this comment and run Flow. */
35+
return <MJScrollView {...props} />;
36+
}
37+
},
38+
}
39+
40+
render() {
41+
return (
42+
/* $FlowFixMe(>=0.53.0 site=react_native_fb,react_native_oss) This
43+
* comment suppresses an error when upgrading Flow's support for React.
44+
* To see the error delete this comment and run Flow. */
45+
<MJListView
46+
{...this.props}
47+
dataSource={this.state.ds}
48+
ref={this._captureRef}
49+
renderRow={this._renderRow}
50+
renderFooter={this.props.FooterComponent && this._renderFooter}
51+
renderSectionHeader={this.props.sections && this._renderSectionHeader}
52+
renderSeparator={this.props.SeparatorComponent && this._renderSeparator}
53+
/>
54+
);
55+
}
56+
}

MJRefresh.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,12 @@ import {
77
ViewPropTypes as RNViewPropTypes,
88
findNodeHandle,
99
UIManager,
10-
ScrollView as NativeScrollView,
1110
Platform,
12-
ListView as NativeListView,
1311
} from 'react-native';
1412
import PropTypes from 'prop-types'
1513
import MJScrollView from './MJScrollView'
1614
import MJListView from './MJListView'
15+
import MJFlatlist from './MJFlatList'
1716
const ViewPropTypes = RNViewPropTypes || View.propTypes;
1817
const UnimplementedView = require('react-native/Libraries/Components/UnimplementedViews/UnimplementedView')
1918
//Android平台未实现RCTMJRefreshView
@@ -79,6 +78,7 @@ MJRefresh.propTypes={
7978
onPulling:PropTypes.func,
8079
...ViewPropTypes
8180
}
82-
export const ScrollView = Platform.OS === 'ios' ? MJScrollView : NativeScrollView;
83-
export const ListView = Platform.OS === 'ios' ? MJListView : NativeListView;
81+
export const ScrollView = MJScrollView;
82+
export const ListView = MJListView;
83+
export const FlatList = MJFlatlist;
8484
export default MJRefresh;

0 commit comments

Comments
 (0)