Skip to content

Commit

Permalink
RN: Update {use,}Pressability Docblocks (#42187)
Browse files Browse the repository at this point in the history
Summary:
Pull Request resolved: #42187

Updates the docblocks for `Pressability` and `usePressability`, as suggested in the code review for {D52388699}.

Changelog:
[General][Changed] Updated Pressability/usePressability Docblocks

Reviewed By: sammy-SC

Differential Revision: D52604388

fbshipit-source-id: e82dd6caa46fe69281e996cbdb8b8e5105b46955
  • Loading branch information
yungsters authored and facebook-github-bot committed Jan 9, 2024
1 parent f7f9250 commit 0fd7bd3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/react-native/Libraries/Pressability/Pressability.js
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,7 @@ const DEFAULT_MIN_PRESS_DURATION = 130;

const DEFAULT_LONG_PRESS_DEACTIVATION_DISTANCE = 10;
let longPressDeactivationDistance = DEFAULT_LONG_PRESS_DEACTIVATION_DISTANCE;

/**
* Pressability implements press handling capabilities.
*
Expand All @@ -313,7 +314,8 @@ let longPressDeactivationDistance = DEFAULT_LONG_PRESS_DEACTIVATION_DISTANCE;
* bounds should trigger deactivation, but moving the same finger back within an
* element's bounds should trigger reactivation.
*
* In order to use `Pressability`, do the following:
* This should be consumed by functional components using `usePressability`. The
* following steps are only relevant for using `Pressability` in classes:
*
* 1. Instantiate `Pressability` and store it on your component's state.
*
Expand All @@ -330,7 +332,15 @@ let longPressDeactivationDistance = DEFAULT_LONG_PRESS_DEACTIVATION_DISTANCE;
* <View {...this.state.pressability.getEventHandlers()} />
* );
*
* 3. Reset `Pressability` when your component unmounts.
* 3. Update `Pressability` when your component mounts, updates, and unmounts.
*
* componentDidMount() {
* this.state.pressability.configure(...);
* }
*
* componentDidUpdate() {
* this.state.pressability.configure(...);
* }
*
* componentWillUnmount() {
* this.state.pressability.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,13 @@ import {useEffect, useRef} from 'react';
* Creates a persistent instance of `Pressability` that automatically configures
* itself and resets. Accepts null `config` to support lazy initialization. Once
* initialized, will not un-initialize until the component has been unmounted.
*
* In order to use `usePressability`, do the following:
*
* const config = useMemo(...);
* const eventHandlers = usePressability(config);
* const pressableView = <View {...eventHandlers} />;
*
*/
export default function usePressability(
config: ?PressabilityConfig,
Expand Down

0 comments on commit 0fd7bd3

Please sign in to comment.