mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
cab4da7288
Summary: Starting to upstream keyboard-related features from React Native Windows - this is the Android implementation. Exposing onFocus and onBlur callbacks on Pressable; they're already declared for View in ViewPropTypes.js, which Pressable wraps. Registering event listeners in ReactViewManager to listen for native focus events. ## Changelog <!-- Help reviewers and the release process by writing your own changelog entry. For an example, see: https://github.com/facebook/react-native/wiki/Changelog --> [Android] [Added] - Add onFocus/onBlur for Pressable on Android. Pull Request resolved: https://github.com/facebook/react-native/pull/30405 Test Plan: Tested on v63-stable, since building master on Windows is now broken. Screenshots from RNTester running on the emulator:   Reviewed By: mdvacca Differential Revision: D25444566 Pulled By: appden fbshipit-source-id: ce0efd3e3b199a508df0ba1ce484b4de17471432
74 lines
1.9 KiB
JavaScript
74 lines
1.9 KiB
JavaScript
/**
|
|
* Copyright (c) Facebook, Inc. and its affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
* @flow strict-local
|
|
*/
|
|
|
|
'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;
|
|
|
|
/**
|
|
* The most fundamental component for building a UI, View is a container that
|
|
* supports layout with flexbox, style, some touch handling, and accessibility
|
|
* controls.
|
|
*
|
|
* @see https://reactnative.dev/docs/view.html
|
|
*/
|
|
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}
|
|
/>
|
|
</TextAncestor.Provider>
|
|
);
|
|
});
|
|
|
|
View.displayName = 'View';
|
|
|
|
module.exports = View;
|