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 9 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,236 changes: 615 additions & 621 deletions Libraries/Components/TextInput/TextInput.js

Large diffs are not rendered by default.

148 changes: 85 additions & 63 deletions Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const React = require('React');
const Touchable = require('Touchable');
const TouchableWithoutFeedback = require('TouchableWithoutFeedback');

const createReactClass = require('create-react-class');
const reactMixin = require('@ericlewis/react-mixin');

import type {EdgeInsetsProp} from 'EdgeInsetsPropType';
import type {ViewStyleProp} from 'StyleSheet';
Expand All @@ -40,7 +40,7 @@ type Props = $ReadOnly<{|
onPressAnimationComplete?: ?() => void,
pressRetentionOffset?: ?EdgeInsetsProp,
releaseVelocity?: ?number,
releaseBounciness?: ?number,
releaseBounciness: ?number,
style?: ?ViewStyleProp,
|}>;

Expand All @@ -51,92 +51,81 @@ 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 {
...this.touchableGetInitialState(),
class TouchableBounce extends React.Component<Props, State> {
static defaultProps = {
releaseBounciness: 10,
releaseVelocity: 10,
};

touchableHandleResponderGrant: ?(
event: PressEvent,
dispatchID: string,
) => void;
touchableHandleStartShouldSetResponder: () => boolean;
touchableHandleResponderMove: ?(event: PressEvent) => void;
touchableHandleResponderRelease: ?(event: PressEvent) => void;
touchableHandleResponderTerminate: ?(event: PressEvent) => void;
touchableHandleResponderTerminationRequest: ?() => boolean;

constructor(props: Props) {
super(props);

Object.keys(Touchable.Mixin.withoutDefaultFocusAndBlur).forEach(name => {
if ((this: any)[name] && (this: any)[name].bind) {
(this: any)[name] = (this: any)[name].bind(this);
}
});
ericlewis marked this conversation as resolved.
Show resolved Hide resolved

this.state = {
...Touchable.Mixin.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 +147,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 +188,40 @@ 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
};

reactMixin.onClass(TouchableBounce, NativeMethodsMixin);
reactMixin.onClass(TouchableBounce, Touchable.Mixin.withoutDefaultFocusAndBlur);

module.exports = TouchableBounce;
Loading