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

Make AnimatedComponents and Touchables strict mode compatible #24218

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
12 changes: 4 additions & 8 deletions Libraries/Animated/src/createAnimatedComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ function createAnimatedComponent(Component: any): any {

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

this._attachProps(this.props);
}

componentWillUnmount() {
Expand All @@ -46,10 +48,6 @@ function createAnimatedComponent(Component: any): any {
this._component.setNativeProps(props);
}

UNSAFE_componentWillMount() {
this._attachProps(this.props);
}

componentDidMount() {
if (this._invokeAnimatedPropsCallbackOnMount) {
this._invokeAnimatedPropsCallbackOnMount = false;
Expand Down Expand Up @@ -131,11 +129,9 @@ function createAnimatedComponent(Component: any): any {
oldPropsAnimated && oldPropsAnimated.__detach();
}

UNSAFE_componentWillReceiveProps(newProps) {
this._attachProps(newProps);
}

componentDidUpdate(prevProps) {
this._attachProps(this.props);

if (this._component !== this._prevComponent) {
this._propsAnimated.setNativeView(this._component);
}
Expand Down
40 changes: 26 additions & 14 deletions Libraries/Components/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const View = require('View');
const keyMirror = require('fbjs/lib/keyMirror');
const normalizeColor = require('normalizeColor');

import type {PressEvent} from 'CoreEventTypes';
import type {SyntheticEvent, PressEvent} from 'CoreEventTypes';
import type {EdgeInsetsProp} from 'EdgeInsetsPropType';

const extractSingleTouch = nativeEvent => {
Expand Down Expand Up @@ -149,6 +149,22 @@ type State =
| typeof States.RESPONDER_ACTIVE_LONG_PRESS_OUT
| typeof States.ERROR;

export type TouchableState = {|
touchable: {
touchState: ?State,
responderID: ?number,
},
|};

type TargetEvent = SyntheticEvent<
$ReadOnly<{|
target: number,
|}>,
>;

export type BlurEvent = TargetEvent;
export type FocusEvent = TargetEvent;

/*
* Quick lookup map for states that are considered to be "active"
*/
Expand Down Expand Up @@ -576,9 +592,9 @@ const TouchableMixin = {
* currently has the focus. Most platforms only support a single element being
* focused at a time, in which case there may have been a previously focused
* element that was blurred just prior to this. This can be overridden when
* using `Touchable.Mixin.withoutDefaultFocusAndBlur`.
* using `Touchable.MixinWithoutDefaultFocusAndBlur`.
*/
touchableHandleFocus: function(e: Event) {
touchableHandleFocus: function(e: FocusEvent) {
this.props.onFocus && this.props.onFocus(e);
},

Expand All @@ -588,9 +604,9 @@ const TouchableMixin = {
* no longer has focus. Most platforms only support a single element being
* focused at a time, in which case the focus may have moved to another.
* This can be overridden when using
* `Touchable.Mixin.withoutDefaultFocusAndBlur`.
* `Touchable.MixinWithoutDefaultFocusAndBlur`.
*/
touchableHandleBlur: function(e: Event) {
touchableHandleBlur: function(e: BlurEvent) {
this.props.onBlur && this.props.onBlur(e);
},

Expand Down Expand Up @@ -900,8 +916,6 @@ const TouchableMixin = {
}
}
},

withoutDefaultFocusAndBlur: {},
};

/**
Expand All @@ -910,15 +924,13 @@ const TouchableMixin = {
* be set on TV platforms, without breaking existing implementations of
* `Touchable`.
*/
const {
touchableHandleFocus,
touchableHandleBlur,
...TouchableMixinWithoutDefaultFocusAndBlur
} = TouchableMixin;
TouchableMixin.withoutDefaultFocusAndBlur = TouchableMixinWithoutDefaultFocusAndBlur;
const TouchableMixinWithoutDefaultFocusAndBlur = {...TouchableMixin};
delete TouchableMixinWithoutDefaultFocusAndBlur.touchableHandleFocus;
delete TouchableMixinWithoutDefaultFocusAndBlur.touchableHandleBlur;

const Touchable = {
Mixin: TouchableMixin,
MixinWithoutDefaultFocusAndBlur: TouchableMixinWithoutDefaultFocusAndBlur,
TOUCH_TARGET_DEBUG: false, // Highlights all touchable targets. Toggle with Inspector.
/**
* Renders a debugging overlay to visualize touch target with hitSlop (might not work on Android).
Expand All @@ -928,7 +940,7 @@ const Touchable = {
hitSlop,
}: {
color: string | number,
hitSlop: EdgeInsetsProp,
hitSlop: ?EdgeInsetsProp,
}) => {
if (!Touchable.TOUCH_TARGET_DEBUG) {
return null;
Expand Down
Loading