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

Trigger onFocus/onBlur instead of onPressIn/onPressOut (eventually, but for now just deprecate) #18470

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
31 changes: 29 additions & 2 deletions Libraries/Components/Touchable/Touchable.js
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,17 @@ const TouchableMixin = {
evt.dispatchConfig = {};
if (myTag === evt.tag) {
if (evt.eventType === 'focus') {
cmp.touchableHandleActivePressIn &&
if (cmp.touchableHandleActivePressIn) {
console.warn('Using `touchableHandleActivePressIn` or `onPressIn` to listen for focus events is deprecated. Use `touchableHandleFocus` or `onFocus` instead.');
cmp.touchableHandleActivePressIn(evt);
}
cmp.touchableHandleFocus(evt);
} else if (evt.eventType === 'blur') {
cmp.touchableHandleActivePressOut &&
if (cmp.touchableHandleActivePressOut) {
console.warn('Using `touchableHandleActivePressOut` or `onPressOut` to listen for blur events is deprecated. Use `touchableHandleBlur` or `onBlur` instead.');
cmp.touchableHandleActivePressOut(evt);
}
cmp.touchableHandleBlur(evt);
} else if (evt.eventType === 'select') {
cmp.touchableHandlePress &&
!cmp.props.disabled &&
Expand Down Expand Up @@ -528,6 +534,27 @@ const TouchableMixin = {
}
},

/**
* Invoked when the item receives focus. Mixers might override this to
* visually distinguish the `VisualRect` so that the user knows that it
* 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.
*/
touchableHandleFocus: function (e: Event) {
this.props.onFocus && this.props.onFocus(e);
},

/**
* Invoked when the item loses focus. Mixers might override this to
* visually distinguish the `VisualRect` so that the user knows that it
* 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.
*/
touchableHandleBlur: function (e: Event) {
this.props.onBlur && this.props.onBlur(e);
},

// ==== Abstract Application Callbacks ====

/**
Expand Down
1 change: 0 additions & 1 deletion Libraries/Components/Touchable/TouchableBounce.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ const TouchableBounce = ((createReactClass({

propTypes: {
...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.
Expand Down
12 changes: 12 additions & 0 deletions Libraries/Components/Touchable/TouchableWithoutFeedback.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,18 @@ const TouchableWithoutFeedback = ((createReactClass({
PropTypes.oneOf(AccessibilityTraits),
PropTypes.arrayOf(PropTypes.oneOf(AccessibilityTraits)),
]),
/**
* When `accessible` is true (which is the default) this may be called when
* the OS-specific concept of "focus" occurs. Some platforms may not have
* the concept of focus.
*/
onFocus: PropTypes.func,
/**
* When `accessible` is true (which is the default) this may be called when
* the OS-specific concept of "blur" occurs, meaning the element lost focus.
* Some platforms may not have the concept of blur.
*/
onBlur: PropTypes.func,
/**
* If true, disable all interactions for this component.
*/
Expand Down