Authored by 张丽霞

对react源码的需改,主要集中在数据曝光和下拉刷新,下拉刷新后面可以替换为RN提供的刷新模块

... ... @@ -39,6 +39,8 @@ const requireNativeComponent = require('requireNativeComponent');
const warning = require('fbjs/lib/warning');
const resolveAssetSource = require('resolveAssetSource');
const RCTScrollViewManager = require('NativeModules').ScrollViewManager;
import type {NativeMethodsMixinType} from 'ReactNativeTypes';
/**
... ... @@ -467,6 +469,23 @@ const ScrollView = createReactClass({
'always',
'never',
]),
/**
pull to refresh
*/
enablePullToRefresh: PropTypes.bool,
isOnPullToRefresh: PropTypes.bool,
onRefreshData: PropTypes.func,
onFinishRefreshData: PropTypes.func,
/**
埋点
*/
yh_exposureData: PropTypes.any,
yh_viewVisible: PropTypes.bool,
/**
* When true, ScrollView will emit updateChildFrames data in scroll events,
* otherwise will not compute or emit child frame data. This only exists
... ... @@ -503,6 +522,24 @@ const ScrollView = createReactClass({
_scrollAnimatedValueAttachment: (null: ?{detach: () => void}),
_stickyHeaderRefs: (new Map(): Map<number, ScrollViewStickyHeader>),
_headerLayoutYs: (new Map(): Map<string, number>),
yh_updateVisibleSubViews: function() {
RCTScrollViewManager.yh_updateVisibleSubViews(
ReactNative.findNodeHandle(this._scrollViewRef)
);
},
startPullToRefresh: function() {
RCTScrollViewManager.startPullToRefresh(
ReactNative.findNodeHandle(this._scrollViewRef)
);
},
stopPullToRefresh: function() {
RCTScrollViewManager.stopPullToRefresh(
ReactNative.findNodeHandle(this._scrollViewRef)
);
},
getInitialState: function() {
return {
...this.scrollResponderMixinGetInitialState(),
... ...
... ... @@ -178,6 +178,8 @@ const TouchableHighlight = createReactClass({
* @platform ios
*/
tvParallaxProperties: PropTypes.object,
yh_exposureData: PropTypes.object,
},
mixins: [NativeMethodsMixin, Touchable.Mixin],
... ... @@ -304,6 +306,7 @@ const TouchableHighlight = createReactClass({
const child = React.Children.only(this.props.children);
return (
<View
yh_exposureData={this.props.yh_exposureData}
accessible={this.props.accessible !== false}
accessibilityLabel={this.props.accessibilityLabel}
accessibilityComponentType={this.props.accessibilityComponentType}
... ...
... ... @@ -139,6 +139,8 @@ var TouchableOpacity = createReactClass({
* Apple TV parallax effects
*/
tvParallaxProperties: PropTypes.object,
yh_exposureData: PropTypes.object,
},
getDefaultProps: function() {
... ... @@ -243,6 +245,7 @@ var TouchableOpacity = createReactClass({
render: function() {
return (
<Animated.View
yh_exposureData={this.props.yh_exposureData}
accessible={this.props.accessible !== false}
accessibilityLabel={this.props.accessibilityLabel}
accessibilityComponentType={this.props.accessibilityComponentType}
... ...
... ... @@ -26,7 +26,7 @@ const requireNativeComponent = require('requireNativeComponent');
import type {ViewProps} from 'ViewPropTypes';
import type {ViewChildContext} from 'ViewContext';
import PropTypes from 'prop-types';
export type Props = ViewProps;
/**
... ... @@ -46,7 +46,13 @@ const View = createReactClass({
// exists for DEV mode. However it's important for them to be declared.
// If the object passed to `createClass` specifies `propTypes`, Flow will
// create a static type from it.
propTypes: ViewPropTypes,
propTypes: {
yh_exposureData: PropTypes.object,
yh_viewVisible: PropTypes.bool,
...ViewPropTypes
},
/**
* `NativeMethodsMixin` will look for this when invoking `setNativeProps`. We
... ...
... ... @@ -437,4 +437,10 @@ module.exports = {
* See http://facebook.github.io/react-native/docs/view.html#needsoffscreenalphacompositing
*/
needsOffscreenAlphaCompositing: PropTypes.bool,
yh_exposureData: PropTypes.object,
yh_viewVisible: PropTypes.bool,
};
... ...
... ... @@ -243,6 +243,12 @@ var ListView = createReactClass({
enableEmptySections: PropTypes.bool,
},
yh_updateVisibleSubViews: function() {
if (this._scrollComponent && this._scrollComponent.yh_updateVisibleSubViews) {
this._scrollComponent.yh_updateVisibleSubViews();
}
},
/**
* Exports some data, e.g. for perf investigations or analytics.
*/
... ... @@ -338,7 +344,7 @@ var ListView = createReactClass({
renderScrollComponent: props => <ScrollView {...props} />,
scrollRenderAheadDistance: DEFAULT_SCROLL_RENDER_AHEAD,
onEndReachedThreshold: DEFAULT_END_REACHED_THRESHOLD,
stickySectionHeadersEnabled: Platform.OS === 'ios',
stickySectionHeadersEnabled: true,
stickyHeaderIndices: [],
};
},
... ...
... ... @@ -280,6 +280,12 @@ class SectionList<SectionT: SectionBase<any>> extends React.PureComponent<
this._wrapperListRef.scrollToLocation(params);
}
setNativeProps(props: Object) {
if (this._wrapperListRef) {
this._wrapperListRef.setNativeProps(props);
}
}
/**
* Tells the list an interaction has occurred, which should trigger viewability calculations, e.g.
* if `waitForInteractions` is true and the user has not scrolled. This is typically called by
... ...
... ... @@ -141,6 +141,12 @@ class VirtualizedSectionList<SectionT: SectionBase> extends React.PureComponent<
state: State;
setNativeProps(props: Object) {
if (this._listRef) {
this._listRef.setNativeProps(props);
}
}
static defaultProps: DefaultProps = {
...VirtualizedList.defaultProps,
data: [],
... ...