Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove create-react-class dependency #23724

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,240 changes: 619 additions & 621 deletions Libraries/Components/TextInput/TextInput.js

Large diffs are not rendered by default.

130 changes: 68 additions & 62 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ const React = require('React');
const Touchable = require('Touchable');
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');

const createReactClass = require('create-react-class');

import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type {ViewStyleProp} from 'StyleSheet';
import type {Props as TouchableWithoutFeedbackProps} from 'TouchableWithoutFeedback';
Expand Down Expand Up @@ -51,92 +49,66 @@ type Props = $ReadOnly<{|
* `TouchableMixin` expects us to implement some abstract methods to handle
* interesting interactions such as `handleTouchablePress`.
*/
const TouchableBounce = ((createReactClass({
displayName: 'TouchableBounce',
mixins: [Touchable.Mixin.withoutDefaultFocusAndBlur, NativeMethodsMixin],

propTypes: {
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
...TouchableWithoutFeedback.propTypes,
// The function passed takes a callback to start the animation which should
// be run after this onPress handler is done. You can use this (for example)
// to update UI before starting the animation.
onPressWithCompletion: PropTypes.func,
// the function passed is called after the animation is complete
onPressAnimationComplete: PropTypes.func,
/**
* When the scroll view is disabled, this defines how far your touch may
* move off of the button, before deactivating the button. Once deactivated,
* try moving it back and you'll see that the button is once again
* reactivated! Move it back and forth several times while the scroll view
* is disabled. Ensure you pass in a constant to reduce memory allocations.
*/
pressRetentionOffset: DeprecatedEdgeInsetsPropType,
releaseVelocity: PropTypes.number.isRequired,
releaseBounciness: PropTypes.number.isRequired,
/**
* Style to apply to the container/underlay. Most commonly used to make sure
* rounded corners match the wrapped component.
*/
style: DeprecatedViewPropTypes.style,
},

getDefaultProps: function() {
return {releaseBounciness: 10, releaseVelocity: 10};
},

getInitialState: function(): State {
return {
class TouchableBounce extends React.Component<Props> {
state: State
constructor(props) {
super(props);

Object.assign(this, {
...NativeMethodsMixin,
...Touchable.Mixin.withoutDefaultFocusAndBlur,
})

this.state = {
...this.touchableGetInitialState(),
scale: new Animated.Value(1),
};
},
}

bounceTo: function(
bounceTo = (
value: number,
velocity: number,
bounciness: number,
callback?: ?() => void,
) {
) => {
Animated.spring(this.state.scale, {
toValue: value,
velocity,
bounciness,
useNativeDriver: true,
}).start(callback);
},
}

/**
* `Touchable.Mixin` self callbacks. The mixin will invoke these if they are
* defined on your component.
*/
touchableHandleActivePressIn: function(e: PressEvent) {
touchableHandleActivePressIn = (e: PressEvent) => {
this.bounceTo(0.93, 0.1, 0);
this.props.onPressIn && this.props.onPressIn(e);
},
}

touchableHandleActivePressOut: function(e: PressEvent) {
touchableHandleActivePressOut = (e: PressEvent) => {
this.bounceTo(1, 0.4, 0);
this.props.onPressOut && this.props.onPressOut(e);
},
}

touchableHandleFocus: function(e: Event) {
touchableHandleFocus = (e: Event) => {
if (Platform.isTV) {
this.bounceTo(0.93, 0.1, 0);
}
this.props.onFocus && this.props.onFocus(e);
},
}

touchableHandleBlur: function(e: Event) {
touchableHandleBlur = (e: Event) => {
if (Platform.isTV) {
this.bounceTo(1, 0.4, 0);
}
this.props.onBlur && this.props.onBlur(e);
},
}

touchableHandlePress: function(e: PressEvent) {
touchableHandlePress = (e: PressEvent) => {
const onPressWithCompletion = this.props.onPressWithCompletion;
if (onPressWithCompletion) {
onPressWithCompletion(() => {
Expand All @@ -158,21 +130,21 @@ const TouchableBounce = ((createReactClass({
this.props.onPressAnimationComplete,
);
this.props.onPress && this.props.onPress(e);
},
}

touchableGetPressRectOffset: function(): typeof PRESS_RETENTION_OFFSET {
touchableGetPressRectOffset = (): typeof PRESS_RETENTION_OFFSET => {
return this.props.pressRetentionOffset || PRESS_RETENTION_OFFSET;
},
}

touchableGetHitSlop: function(): ?EdgeInsetsProp {
touchableGetHitSlop = (): ?EdgeInsetsProp => {
return this.props.hitSlop;
},
}

touchableGetHighlightDelayMS: function(): number {
touchableGetHighlightDelayMS(): number {
return 0;
},
}

render: function(): React.Element<any> {
render(): React.Element<any> {
return (
<Animated.View
style={[{transform: [{scale: this.state.scale}]}, this.props.style]}
Expand All @@ -199,7 +171,41 @@ const TouchableBounce = ((createReactClass({
})}
</Animated.View>
);
},
}): any): React.ComponentType<Props>);
ericlewis marked this conversation as resolved.
Show resolved Hide resolved
ericlewis marked this conversation as resolved.
Show resolved Hide resolved
}

TouchableBounce.displayName = 'TouchableBounce';

TouchableBounce.propTypes = {
/* $FlowFixMe(>=0.89.0 site=react_native_fb) This comment suppresses an
* error found when Flow v0.89 was deployed. To see the error, delete this
* comment and run Flow. */
...TouchableWithoutFeedback.propTypes,
// The function passed takes a callback to start the animation which should
// be run after this onPress handler is done. You can use this (for example)
// to update UI before starting the animation.
onPressWithCompletion: PropTypes.func,
// the function passed is called after the animation is complete
onPressAnimationComplete: PropTypes.func,
/**
* When the scroll view is disabled, this defines how far your touch may
* move off of the button, before deactivating the button. Once deactivated,
* try moving it back and you'll see that the button is once again
* reactivated! Move it back and forth several times while the scroll view
* is disabled. Ensure you pass in a constant to reduce memory allocations.
*/
pressRetentionOffset: DeprecatedEdgeInsetsPropType,
releaseVelocity: PropTypes.number.isRequired,
releaseBounciness: PropTypes.number.isRequired,
/**
* Style to apply to the container/underlay. Most commonly used to make sure
* rounded corners match the wrapped component.
*/
style: DeprecatedViewPropTypes.style,
ericlewis marked this conversation as resolved.
Show resolved Hide resolved
};

TouchableBounce.defaultProps = {
releaseBounciness: 10,
releaseVelocity: 10,
};

module.exports = TouchableBounce;
Loading