Back out "Add onFocus and onBlur to Pressable."

Summary:
I suspect it's causing T82781515.

Changelog:
[Category][Type] - Backout of "[react-native][PR] Add onFocus and onBlur to Pressable."

Reviewed By: p-sun

Differential Revision: D25864414

fbshipit-source-id: efba9136edba97d5bd2a0de15f9ddae7dfd24e51
This commit is contained in:
Valentin Shergin 2021-01-10 13:54:36 -08:00 коммит произвёл Facebook GitHub Bot
Родитель dfd8d9ae91
Коммит e37e56b042
9 изменённых файлов: 16 добавлений и 131 удалений

Просмотреть файл

@ -25,12 +25,7 @@ import type {
import {PressabilityDebugView} from '../../Pressability/PressabilityDebug';
import usePressability from '../../Pressability/usePressability';
import {normalizeRect, type RectOrSize} from '../../StyleSheet/Rect';
import type {
LayoutEvent,
PressEvent,
BlurEvent,
FocusEvent,
} from '../../Types/CoreEventTypes';
import type {LayoutEvent, PressEvent} from '../../Types/CoreEventTypes';
import View from '../View/View';
type ViewStyleProp = $ElementType<React.ElementConfig<typeof View>, 'style'>;
@ -110,16 +105,6 @@ type Props = $ReadOnly<{|
*/
onPressOut?: ?(event: PressEvent) => void,
/**
* Called after the element loses focus.
*/
onBlur?: ?(event: BlurEvent) => mixed,
/**
* Called after the element is focused.
*/
onFocus?: ?(event: FocusEvent) => mixed,
/**
* Either view styles or a function that receives a boolean reflecting whether
* the component is currently pressed and returns view styles.
@ -169,8 +154,6 @@ function Pressable(props: Props, forwardedRef): React.Node {
onPress,
onPressIn,
onPressOut,
onBlur,
onFocus,
pressRetentionOffset,
style,
testOnly_pressed,
@ -224,8 +207,6 @@ function Pressable(props: Props, forwardedRef): React.Node {
onPressOut(event);
}
},
onBlur,
onFocus,
}),
[
android_disableSound,
@ -237,8 +218,6 @@ function Pressable(props: Props, forwardedRef): React.Node {
onPress,
onPressIn,
onPressOut,
onBlur,
onFocus,
pressRetentionOffset,
setPressed,
unstable_pressDelay,

Просмотреть файл

@ -11,14 +11,10 @@
'use strict';
import type {ViewProps} from './ViewPropTypes';
import type {BlurEvent, FocusEvent} from '../../Types/CoreEventTypes';
const React = require('react');
import ViewNativeComponent from './ViewNativeComponent';
const TextAncestor = require('../../Text/TextAncestor');
const TextInputState = require('../TextInput/TextInputState');
import type {HostComponent} from '../../Renderer/shims/ReactNativeTypes';
const setAndForwardRef = require('../../Utilities/setAndForwardRef');
const {useRef} = React;
export type Props = ViewProps;
@ -33,37 +29,9 @@ const View: React.AbstractComponent<
ViewProps,
React.ElementRef<typeof ViewNativeComponent>,
> = React.forwardRef((props: ViewProps, forwardedRef) => {
const viewRef = useRef<null | React.ElementRef<HostComponent<mixed>>>(null);
const _setNativeRef = setAndForwardRef({
getForwardedRef: () => forwardedRef,
setLocalRef: ref => {
viewRef.current = ref;
},
});
const _onBlur = (event: BlurEvent) => {
TextInputState.blurInput(viewRef.current);
if (props.onBlur) {
props.onBlur(event);
}
};
const _onFocus = (event: FocusEvent) => {
TextInputState.focusInput(viewRef.current);
if (props.onFocus) {
props.onFocus(event);
}
};
return (
<TextAncestor.Provider value={false}>
<ViewNativeComponent
{...props}
onBlur={_onBlur}
onFocus={_onFocus}
ref={_setNativeRef}
/>
<ViewNativeComponent {...props} ref={forwardedRef} />
</TextAncestor.Provider>
);
});

Просмотреть файл

@ -1,4 +1,4 @@
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "react_native_target", "rn_android_library")
load("//tools/build_defs/oss:rn_defs.bzl", "react_native_dep", "rn_android_library")
rn_android_library(
name = "common",
@ -18,8 +18,5 @@ rn_android_library(
"PUBLIC",
],
deps = [
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/bridge:bridge"),
],
)

Просмотреть файл

@ -21,7 +21,6 @@ rn_android_library(
react_native_target("java/com/facebook/react/modules/core:core"),
react_native_target("java/com/facebook/react/uimanager:uimanager"),
react_native_target("java/com/facebook/react/uimanager/annotations:annotations"),
react_native_target("java/com/facebook/react/views/common:common"),
react_native_target("java/com/facebook/react/views/imagehelper:imagehelper"),
react_native_target("java/com/facebook/react/views/scroll:scroll"),
react_native_target("java/com/facebook/react/views/text:text"),

Просмотреть файл

@ -5,19 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.views.common;
package com.facebook.react.views.textinput;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
/** Event emitted by a native view when it loses focus. */
public class ReactViewBlurEvent extends Event<ReactViewBlurEvent> {
/** Event emitted by EditText native view when it loses focus. */
/* package */ class ReactTextInputBlurEvent extends Event<ReactTextInputBlurEvent> {
private static final String EVENT_NAME = "topBlur";
public ReactViewBlurEvent(int viewId) {
public ReactTextInputBlurEvent(int viewId) {
super(viewId);
}

Просмотреть файл

@ -5,19 +5,19 @@
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.views.common;
package com.facebook.react.views.textinput;
import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.WritableMap;
import com.facebook.react.uimanager.events.Event;
import com.facebook.react.uimanager.events.RCTEventEmitter;
/** Event emitted by a native view when it receives focus. */
public class ReactViewFocusEvent extends Event<ReactViewFocusEvent> {
/** Event emitted by EditText native view when it receives focus. */
/* package */ class ReactTextInputFocusEvent extends Event<ReactTextInputFocusEvent> {
private static final String EVENT_NAME = "topFocus";
public ReactViewFocusEvent(int viewId) {
public ReactTextInputFocusEvent(int viewId) {
super(viewId);
}

Просмотреть файл

@ -59,8 +59,6 @@ import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.common.ReactViewBlurEvent;
import com.facebook.react.views.common.ReactViewFocusEvent;
import com.facebook.react.views.imagehelper.ResourceDrawableIdHelper;
import com.facebook.react.views.scroll.ScrollEvent;
import com.facebook.react.views.scroll.ScrollEventType;
@ -976,9 +974,9 @@ public class ReactTextInputManager extends BaseViewManager<ReactEditText, Layout
public void onFocusChange(View v, boolean hasFocus) {
EventDispatcher eventDispatcher = getEventDispatcher(reactContext, editText);
if (hasFocus) {
eventDispatcher.dispatchEvent(new ReactViewFocusEvent(editText.getId()));
eventDispatcher.dispatchEvent(new ReactTextInputFocusEvent(editText.getId()));
} else {
eventDispatcher.dispatchEvent(new ReactViewBlurEvent(editText.getId()));
eventDispatcher.dispatchEvent(new ReactTextInputBlurEvent(editText.getId()));
eventDispatcher.dispatchEvent(
new ReactTextInputEndEditingEvent(

Просмотреть файл

@ -29,8 +29,6 @@ import com.facebook.react.uimanager.ViewProps;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.facebook.react.uimanager.annotations.ReactPropGroup;
import com.facebook.react.uimanager.events.EventDispatcher;
import com.facebook.react.views.common.ReactViewBlurEvent;
import com.facebook.react.views.common.ReactViewFocusEvent;
import com.facebook.yoga.YogaConstants;
import java.util.Locale;
import java.util.Map;
@ -236,7 +234,8 @@ public class ReactViewManager extends ReactClippingViewManager<ReactViewGroup> {
@Override
public void onClick(View v) {
final EventDispatcher mEventDispatcher =
getEventDispatcher((ReactContext) view.getContext(), view);
UIManagerHelper.getEventDispatcherForReactTag(
(ReactContext) view.getContext(), view.getId());
if (mEventDispatcher == null) {
return;
}
@ -255,27 +254,6 @@ public class ReactViewManager extends ReactClippingViewManager<ReactViewGroup> {
}
}
private static EventDispatcher getEventDispatcher(
ReactContext reactContext, ReactViewGroup view) {
return UIManagerHelper.getEventDispatcherForReactTag(reactContext, view.getId());
}
@Override
protected void addEventEmitters(
final ThemedReactContext reactContext, final ReactViewGroup view) {
view.setOnFocusChangeListener(
new View.OnFocusChangeListener() {
public void onFocusChange(View v, boolean hasFocus) {
EventDispatcher eventDispatcher = getEventDispatcher(reactContext, view);
if (hasFocus) {
eventDispatcher.dispatchEvent(new ReactViewFocusEvent(view.getId()));
} else {
eventDispatcher.dispatchEvent(new ReactViewBlurEvent(view.getId()));
}
}
});
}
@ReactProp(name = ViewProps.OVERFLOW)
public void setOverflow(ReactViewGroup view, String overflow) {
view.setOverflow(overflow);

Просмотреть файл

@ -250,32 +250,6 @@ function PressableDisabled() {
);
}
function PressableFocusBlurEvents() {
const [lastEvent, setLastEvent] = useState('');
return (
<View testID="pressable_hit_slop">
<View style={[styles.row, styles.centered]}>
<Pressable
onFocus={() => {
console.log('Focused!');
setLastEvent('Received focus event');
}}
onBlur={() => {
console.log('Blurred!');
setLastEvent('Received blur event');
}}
testID="pressable_focus_blur_button">
<Text style={styles.text}>Use keyboard to move focus to me</Text>
</Pressable>
</View>
<View style={styles.logBox}>
<Text>{lastEvent}</Text>
</View>
</View>
);
}
const styles = StyleSheet.create({
row: {
justifyContent: 'center',
@ -504,12 +478,4 @@ exports.examples = [
return <PressableDisabled />;
},
},
{
title: 'Pressable onFocus/onBlur',
description: ('<Pressable> components can receive focus/blur events.': string),
platform: 'android',
render: function(): React.Node {
return <PressableFocusBlurEvents />;
},
},
];