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 TouchableNativeFeedback strict mode compatible #48522

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import Pressability, {
type PressabilityConfig,
} from '../../Pressability/Pressability';
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
import {findHostInstance_DEPRECATED} from '../../ReactNative/RendererProxy';
import processColor from '../../StyleSheet/processColor';
import Platform from '../../Utilities/Platform';
import {Commands} from '../View/ViewNativeComponent';
Expand Down Expand Up @@ -96,6 +95,13 @@ type State = $ReadOnly<{|
|}>;

class TouchableNativeFeedback extends React.Component<Props, State> {
hostRef: {current: React.ElementRef<typeof View> | null, ...};

constructor(props: Props) {
super(props);
this.hostRef = React.createRef();
}

/**
* Creates a value for the `background` prop that uses the Android theme's
* default background for selectable elements.
Expand Down Expand Up @@ -208,7 +214,7 @@ class TouchableNativeFeedback extends React.Component<Props, State> {

_dispatchPressedStateChange(pressed: boolean): void {
if (Platform.OS === 'android') {
const hostComponentRef = findHostInstance_DEPRECATED(this);
const hostComponentRef = this.hostRef.current;
if (hostComponentRef == null) {
console.warn(
'Touchable: Unable to find HostComponent instance. ' +
Expand All @@ -223,7 +229,7 @@ class TouchableNativeFeedback extends React.Component<Props, State> {
_dispatchHotspotUpdate(event: PressEvent): void {
if (Platform.OS === 'android') {
const {locationX, locationY} = event.nativeEvent;
const hostComponentRef = findHostInstance_DEPRECATED(this);
const hostComponentRef = this.hostRef.current;
if (hostComponentRef == null) {
console.warn(
'Touchable: Unable to find HostComponent instance. ' +
Expand Down Expand Up @@ -292,6 +298,7 @@ class TouchableNativeFeedback extends React.Component<Props, State> {
return React.cloneElement(
element,
{
ref: this.hostRef,
...eventHandlersWithoutBlurAndFocus,
...getBackgroundProp(
this.props.background === undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3826,6 +3826,8 @@ type State = $ReadOnly<{|
pressability: Pressability,
|}>;
declare class TouchableNativeFeedback extends React.Component<Props, State> {
hostRef: { current: React.ElementRef<typeof View> | null, ... };
constructor(props: Props): void;
static SelectableBackground: (rippleRadius: ?number) => $ReadOnly<{|
attribute: \\"selectableItemBackground\\",
type: \\"ThemeAttrAndroid\\",
Expand Down
Loading