Skip to content

Instantly share code, notes, and snippets.

@orlando
Last active August 30, 2016 21:37
Show Gist options
  • Save orlando/45c69c716c1dffd0efc90a33ec9ef03b to your computer and use it in GitHub Desktop.
Save orlando/45c69c716c1dffd0efc90a33ec9ef03b to your computer and use it in GitHub Desktop.
ViewPagerAndroid.android.js babel issue
var ViewPagerAndroid = function (_React$Component) {
babelHelpers.inherits(ViewPagerAndroid, _React$Component);
function ViewPagerAndroid() {
var _ref;
var _temp, _this, _ret;
babelHelpers.classCallCheck(this, ViewPagerAndroid);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this = babelHelpers.possibleConstructorReturn(this, (_ref = ViewPagerAndroid.__proto__ || Object.getPrototypeOf(ViewPagerAndroid)).call.apply(_ref, [this].concat(args))), _this), _this.getInnerViewNode = function () {
return _this.refs[VIEWPAGER_REF].getInnerViewNode();
}, _this._childrenWithOverridenStyle = function () {
// Override styles so that each page will fill the parent. Native component
// will handle positioning of elements, so it's not important to offset
// them correctly.
return React.Children.map(_this.props.children, function (child) {
if (!child) {
return null;
}
var newProps = babelHelpers.extends({}, child.props, {
style: [child.props.style, {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
width: undefined,
height: undefined
}],
collapsable: false
});
if (child.type && child.type.displayName && child.type.displayName !== 'RCTView' && child.type.displayName !== 'View') {
console.warn('Each ViewPager child must be a <View>. Was ' + child.type.displayName);
}
return ReactElement.createElement(child.type, newProps);
});
}, _this._onPageScroll = function (e) {
if (_this.props.onPageScroll) {
_this.props.onPageScroll(e);
}
if (_this.props.keyboardDismissMode === 'on-drag') {
dismissKeyboard();
}
}, _this._onPageScrollStateChanged = function (e) {
if (_this.props.onPageScrollStateChanged) {
_this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState);
}
}, _this._onPageSelected = function (e) {
if (_this.props.onPageSelected) {
_this.props.onPageSelected(e);
}
}, _this.setPage = function (selectedPage) {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(_this), UIManager.AndroidViewPager.Commands.setPage, [selectedPage]);
}, _this.setPageWithoutAnimation = function (selectedPage) {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(_this), UIManager.AndroidViewPager.Commands.setPageWithoutAnimation, [selectedPage]);
}, _temp), babelHelpers.possibleConstructorReturn(_this, _ret);
}
babelHelpers.createClass(ViewPagerAndroid, [{
key: 'componentDidMount',
value: function componentDidMount() {
if (this.props.initialPage) {
this.setPageWithoutAnimation(this.props.initialPage);
}
}
/**
* A helper function to scroll to a specific page in the ViewPager.
* The transition between pages will be animated.
*/
/**
* A helper function to scroll to a specific page in the ViewPager.
* The transition between pages will *not* be animated.
*/
}, {
key: 'render',
value: function render() {
return React.createElement(NativeAndroidViewPager, babelHelpers.extends({}, this.props, {
ref: VIEWPAGER_REF,
style: this.props.style,
onPageScroll: this._onPageScroll,
onPageScrollStateChanged: this._onPageScrollStateChanged,
onPageSelected: this._onPageSelected,
children: this._childrenWithOverridenStyle()
}));
}
}]);
return ViewPagerAndroid;
}(React.Component);
var ViewPagerAndroid = function (_React$Component) {
babelHelpers.inherits(ViewPagerAndroid, _React$Component);
function ViewPagerAndroid() {
var _ref;
var _temp, _this2, _ret;
babelHelpers.classCallCheck(this, ViewPagerAndroid);
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
return _ret = (_temp = (_this2 = babelHelpers.possibleConstructorReturn(this, (_ref = ViewPagerAndroid.__proto__ || Object.getPrototypeOf(ViewPagerAndroid)).call.apply(_ref, [this].concat(args))), _this2), _this2.getInnerViewNode = function () {
return _this.refs[VIEWPAGER_REF].getInnerViewNode();
}, _this2._childrenWithOverridenStyle = function () {
// Override styles so that each page will fill the parent. Native component
// will handle positioning of elements, so it's not important to offset
// them correctly.
return React.Children.map(_this.props.children, function (child) {
if (!child) {
return null;
}
var newProps = babelHelpers.extends({}, child.props, {
style: [child.props.style, {
position: 'absolute',
left: 0,
top: 0,
right: 0,
bottom: 0,
width: undefined,
height: undefined
}],
collapsable: false
});
if (child.type && child.type.displayName && child.type.displayName !== 'RCTView' && child.type.displayName !== 'View') {
console.warn('Each ViewPager child must be a <View>. Was ' + child.type.displayName);
}
return ReactElement.createElement(child.type, newProps);
});
}, _this2._onPageScroll = function (e) {
if (_this.props.onPageScroll) {
_this.props.onPageScroll(e);
}
if (_this.props.keyboardDismissMode === 'on-drag') {
dismissKeyboard();
}
}, _this2._onPageScrollStateChanged = function (e) {
if (_this.props.onPageScrollStateChanged) {
_this.props.onPageScrollStateChanged(e.nativeEvent.pageScrollState);
}
}, _this2._onPageSelected = function (e) {
if (_this.props.onPageSelected) {
_this.props.onPageSelected(e);
}
}, _this2.setPage = function (selectedPage) {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(_this), UIManager.AndroidViewPager.Commands.setPage, [selectedPage]);
}, _this2.setPageWithoutAnimation = function (selectedPage) {
UIManager.dispatchViewManagerCommand(ReactNative.findNodeHandle(_this), UIManager.AndroidViewPager.Commands.setPageWithoutAnimation, [selectedPage]);
}, _temp), babelHelpers.possibleConstructorReturn(_this2, _ret);
}
babelHelpers.createClass(ViewPagerAndroid, [{
key: 'componentDidMount',
value: function componentDidMount() {
if (this.props.initialPage) {
this.setPageWithoutAnimation(this.props.initialPage);
}
}
/**
* A helper function to scroll to a specific page in the ViewPager.
* The transition between pages will be animated.
*/
/**
* A helper function to scroll to a specific page in the ViewPager.
* The transition between pages will *not* be animated.
*/
}, {
key: 'render',
value: function render() {
return React.createElement(NativeAndroidViewPager, babelHelpers.extends({}, this.props, {
ref: VIEWPAGER_REF,
style: this.props.style,
onPageScroll: this._onPageScroll,
onPageScrollStateChanged: this._onPageScrollStateChanged,
onPageSelected: this._onPageSelected,
children: this._childrenWithOverridenStyle()
}));
}
}]);
return ViewPagerAndroid;
}(React.Component);

Babel.rc

{
  "passPerPreset": true,
  "presets": [
    "react-native"
  ],
  "plugins": [
    "transform-class-properties"
  ]
}

The difference between both files is the reference to this. Without the plugin, _this2 is used instead of _this (the one called in the render method).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment