mirror of
https://github.com/facebook/react-native.git
synced 2025-11-01 09:14:26 +00:00
Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/35169 This reorganizes typing structure a bit. `Utilities.d.ts` was originally added for utilitiy types but I ended up leaving it a grab bag of types that didn't belong to any individual bit of code. Out of what is in it right now, `Insets` was actually public, and seems to have been imported. We also run into files around the renderer which are [currently overwritten](https://github.com/facebook/react-native/commits/e286da25fc83324363486eb668806aca179f74b3/Libraries/Renderer/implementations/ReactNativeRenderer.d.ts) by the React sync script. Finally, all of the top-level imports of `Utilities` were auto-generated by VS Code, but fail in real apps. I think this is because our tsconfig sets a `baseUrl` to allow resolution from the types folder, so the tooling in the RN repo will use that, but it breaks in real apps that don't have that mapping. This splits all these up into a couple separate directories that are hopefully easier to reason about, and removes `Omit` which has been a builtin type for quite some time (we were actually already using built-in `Omit`). Changelog: [General][Fixed] - Fixup TS Organization Reviewed By: cipolleschi Differential Revision: D40932319 fbshipit-source-id: 0b6e3e3eda603885b4dc01dcb9f5233aa546d128
150 lines
6.2 KiB
TypeScript
150 lines
6.2 KiB
TypeScript
/**
|
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
*
|
|
* This source code is licensed under the MIT license found in the
|
|
* LICENSE file in the root directory of this source tree.
|
|
*
|
|
* @format
|
|
*/
|
|
|
|
import {GestureResponderEvent} from '../../Libraries/Types/CoreEventTypes';
|
|
|
|
/**
|
|
* Gesture recognition on mobile devices is much more complicated than web.
|
|
* A touch can go through several phases as the app determines what the user's intention is.
|
|
* For example, the app needs to determine if the touch is scrolling, sliding on a widget, or tapping.
|
|
* This can even change during the duration of a touch. There can also be multiple simultaneous touches.
|
|
*
|
|
* The touch responder system is needed to allow components to negotiate these touch interactions
|
|
* without any additional knowledge about their parent or child components.
|
|
* This system is implemented in ResponderEventPlugin.js, which contains further details and documentation.
|
|
*
|
|
* Best Practices
|
|
* Users can feel huge differences in the usability of web apps vs. native, and this is one of the big causes.
|
|
* Every action should have the following attributes:
|
|
* Feedback/highlighting- show the user what is handling their touch, and what will happen when they release the gesture
|
|
* Cancel-ability- when making an action, the user should be able to abort it mid-touch by dragging their finger away
|
|
*
|
|
* These features make users more comfortable while using an app,
|
|
* because it allows people to experiment and interact without fear of making mistakes.
|
|
*
|
|
* TouchableHighlight and Touchable*
|
|
* The responder system can be complicated to use.
|
|
* So we have provided an abstract Touchable implementation for things that should be "tappable".
|
|
* This uses the responder system and allows you to easily configure tap interactions declaratively.
|
|
* Use TouchableHighlight anywhere where you would use a button or link on web.
|
|
*/
|
|
export interface GestureResponderHandlers {
|
|
/**
|
|
* A view can become the touch responder by implementing the correct negotiation methods.
|
|
* There are two methods to ask the view if it wants to become responder:
|
|
*/
|
|
|
|
/**
|
|
* Does this view want to become responder on the start of a touch?
|
|
*/
|
|
onStartShouldSetResponder?:
|
|
| ((event: GestureResponderEvent) => boolean)
|
|
| undefined;
|
|
|
|
/**
|
|
* Called for every touch move on the View when it is not the responder: does this view want to "claim" touch responsiveness?
|
|
*/
|
|
onMoveShouldSetResponder?:
|
|
| ((event: GestureResponderEvent) => boolean)
|
|
| undefined;
|
|
|
|
/**
|
|
* If the View returns true and attempts to become the responder, one of the following will happen:
|
|
*/
|
|
|
|
onResponderEnd?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* The View is now responding for touch events.
|
|
* This is the time to highlight and show the user what is happening
|
|
*/
|
|
onResponderGrant?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* Something else is the responder right now and will not release it
|
|
*/
|
|
onResponderReject?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* If the view is responding, the following handlers can be called:
|
|
*/
|
|
|
|
/**
|
|
* The user is moving their finger
|
|
*/
|
|
onResponderMove?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* Fired at the end of the touch, ie "touchUp"
|
|
*/
|
|
onResponderRelease?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
onResponderStart?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* Something else wants to become responder.
|
|
* Should this view release the responder? Returning true allows release
|
|
*/
|
|
onResponderTerminationRequest?:
|
|
| ((event: GestureResponderEvent) => boolean)
|
|
| undefined;
|
|
|
|
/**
|
|
* The responder has been taken from the View.
|
|
* Might be taken by other views after a call to onResponderTerminationRequest,
|
|
* or might be taken by the OS without asking (happens with control center/ notification center on iOS)
|
|
*/
|
|
onResponderTerminate?: ((event: GestureResponderEvent) => void) | undefined;
|
|
|
|
/**
|
|
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
|
|
* where the deepest node is called first.
|
|
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
|
|
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
|
|
*
|
|
* However, sometimes a parent will want to make sure that it becomes responder.
|
|
* This can be handled by using the capture phase.
|
|
* Before the responder system bubbles up from the deepest component,
|
|
* it will do a capture phase, firing on*ShouldSetResponderCapture.
|
|
* So if a parent View wants to prevent the child from becoming responder on a touch start,
|
|
* it should have a onStartShouldSetResponderCapture handler which returns true.
|
|
*/
|
|
onStartShouldSetResponderCapture?:
|
|
| ((event: GestureResponderEvent) => boolean)
|
|
| undefined;
|
|
|
|
/**
|
|
* onStartShouldSetResponder and onMoveShouldSetResponder are called with a bubbling pattern,
|
|
* where the deepest node is called first.
|
|
* That means that the deepest component will become responder when multiple Views return true for *ShouldSetResponder handlers.
|
|
* This is desirable in most cases, because it makes sure all controls and buttons are usable.
|
|
*
|
|
* However, sometimes a parent will want to make sure that it becomes responder.
|
|
* This can be handled by using the capture phase.
|
|
* Before the responder system bubbles up from the deepest component,
|
|
* it will do a capture phase, firing on*ShouldSetResponderCapture.
|
|
* So if a parent View wants to prevent the child from becoming responder on a touch start,
|
|
* it should have a onStartShouldSetResponderCapture handler which returns true.
|
|
*/
|
|
onMoveShouldSetResponderCapture?:
|
|
| ((event: GestureResponderEvent) => boolean)
|
|
| undefined;
|
|
}
|
|
|
|
/**
|
|
* React Native also implements unstable_batchedUpdates
|
|
*/
|
|
export function unstable_batchedUpdates<A, B>(
|
|
callback: (a: A, b: B) => any,
|
|
a: A,
|
|
b: B,
|
|
): void;
|
|
export function unstable_batchedUpdates<A>(callback: (a: A) => any, a: A): void;
|
|
export function unstable_batchedUpdates(callback: () => any): void;
|