Skip to content

Commit 6fa039d

Browse files
MartinSherburnfacebook-github-bot
authored andcommitted
Added ScrollView support for React VR platform
Reviewed By: sahrens Differential Revision: D6727393 fbshipit-source-id: 261d5734d5de3b94fd9eaefb5beab0e2d3074b17
1 parent 46cc490 commit 6fa039d

File tree

1 file changed

+40
-8
lines changed

1 file changed

+40
-8
lines changed

Libraries/Components/ScrollView/ScrollView.js

+40-8
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const requireNativeComponent = require('requireNativeComponent');
3737
* found when Flow v0.54 was deployed. To see the error delete this comment and
3838
* run Flow. */
3939
const warning = require('fbjs/lib/warning');
40+
const resolveAssetSource = require('resolveAssetSource');
4041

4142
import type {NativeMethodsMixinType} from 'ReactNativeTypes';
4243

@@ -470,6 +471,25 @@ const ScrollView = createReactClass({
470471
* @platform ios
471472
*/
472473
DEPRECATED_sendUpdatedChildFrames: PropTypes.bool,
474+
/**
475+
* Optionally an image can be used for the scroll bar thumb. This will
476+
* override the color. While the image is loading or the image fails to
477+
* load the color will be used instead. Use an alpha of 0 in the color
478+
* to avoid seeing it while the image is loading.
479+
*
480+
* - `uri` - a string representing the resource identifier for the image, which
481+
* should be either a local file path or the name of a static image resource
482+
* - `number` - Opaque type returned by something like
483+
* `import IMAGE from './image.jpg'`.
484+
* @platform vr
485+
*/
486+
scrollBarThumbImage: PropTypes.oneOfType([
487+
PropTypes.shape({
488+
uri: PropTypes.string,
489+
}),
490+
// Opaque type returned by import IMAGE from './image.jpg'
491+
PropTypes.number,
492+
]),
473493
},
474494

475495
mixins: [ScrollResponder.Mixin],
@@ -674,21 +694,21 @@ const ScrollView = createReactClass({
674694
render: function() {
675695
let ScrollViewClass;
676696
let ScrollContentContainerViewClass;
677-
if (Platform.OS === 'ios') {
678-
ScrollViewClass = RCTScrollView;
679-
ScrollContentContainerViewClass = RCTScrollContentView;
680-
warning(
681-
!this.props.snapToInterval || !this.props.pagingEnabled,
682-
'snapToInterval is currently ignored when pagingEnabled is true.'
683-
);
684-
} else if (Platform.OS === 'android') {
697+
if (Platform.OS === 'android') {
685698
if (this.props.horizontal) {
686699
ScrollViewClass = AndroidHorizontalScrollView;
687700
ScrollContentContainerViewClass = AndroidHorizontalScrollContentView;
688701
} else {
689702
ScrollViewClass = AndroidScrollView;
690703
ScrollContentContainerViewClass = View;
691704
}
705+
} else {
706+
ScrollViewClass = RCTScrollView;
707+
ScrollContentContainerViewClass = RCTScrollContentView;
708+
warning(
709+
!this.props.snapToInterval || !this.props.pagingEnabled,
710+
'snapToInterval is currently ignored when pagingEnabled is true.'
711+
);
692712
}
693713

694714
invariant(
@@ -805,6 +825,7 @@ const ScrollView = createReactClass({
805825
onTouchMove: this.scrollResponderHandleTouchMove,
806826
onTouchStart: this.scrollResponderHandleTouchStart,
807827
onTouchCancel: this.scrollResponderHandleTouchCancel,
828+
scrollBarThumbImage: resolveAssetSource(this.props.scrollBarThumbImage),
808829
scrollEventThrottle: hasStickyHeaders ? 1 : this.props.scrollEventThrottle,
809830
sendMomentumEvents: (this.props.onMomentumScrollBegin || this.props.onMomentumScrollEnd) ?
810831
true : false,
@@ -910,6 +931,17 @@ if (Platform.OS === 'android') {
910931
nativeOnlyProps,
911932
);
912933
RCTScrollContentView = requireNativeComponent('RCTScrollContentView', View);
934+
} else {
935+
nativeOnlyProps = {
936+
nativeOnly: {
937+
}
938+
};
939+
RCTScrollView = requireNativeComponent(
940+
'RCTScrollView',
941+
null,
942+
nativeOnlyProps,
943+
);
944+
RCTScrollContentView = requireNativeComponent('RCTScrollContentView', View);
913945
}
914946

915947
module.exports = ScrollView;

0 commit comments

Comments
 (0)