Граф коммитов

36 Коммитов

Автор SHA1 Сообщение Дата
Tim Yung 148c98ec80 RN: Resolve Outstanding ESLint Warnings
Summary:
Resolves outstanding ESLint warnings in React Native.

Changelog:
[Internal]

Reviewed By: lunaleaps

Differential Revision: D32291912

fbshipit-source-id: 61337d5a5a0e6ed55f732675e029f4b76d850af9
2021-11-09 21:46:21 -08:00
Rubén Norte 74b91c5073 Revert changes in RN preprocessor
Summary: Changelog: [General][Fixed] Revert changes in Jest preprocessor to fix tests in external projects

Reviewed By: yungsters

Differential Revision: D32250044

fbshipit-source-id: 0ed4c9f7bcfa82349b5c2ec7af2ccda970bbb0ef
2021-11-09 01:15:14 -08:00
Tim Yung 77ecc7ede1 JS: Format with Prettier v2.4.1 [3/n]
Summary:
Changelog:
[General][Internal]

Reviewed By: zertosh

Differential Revision: D31883447

fbshipit-source-id: cbbf85e4bf935096d242336f41bf0cc5d6f92359
2021-11-02 22:14:16 -07:00
Joshua Gross bf1a5ca8f1 Emit all touch events to PerformanceEventEmitter
Summary:
Pressability previously was filtering which events get forwarded through the PerformanceEventEmitter, but this causes issues for native telemetry systems which won't know which events Pressability has skipped (or why).

Also, the "delay ms" no longer has any meaning because the native timestamps and Date.now() have a different time-basis entirely.

Changelog: [Internal]

Differential Revision: D31251300

fbshipit-source-id: f097047ac150e8dddb0f3857d9f375bae2318681
2021-09-30 13:11:36 -07:00
Joshua Gross cbe0e6bf27 Pass nativeTimestamp into PressabilityPerformanceEvent
Summary:
Pass nativeTimestamp into PressabilityPerformanceEvent as a way to uniquely identify events.

Changelog: [Internal]

Differential Revision: D30648544

fbshipit-source-id: 7cb0146f6ff1655f1312e5094535e59268fb2a22
2021-08-30 20:03:28 -07:00
Luna Wei bac2c2c801 Update FlowFixMes to use error codes in react-native-github
Summary:
Changelog:
[Internal] - Add error codes to existing FlowFixMe's

Reviewed By: kacieb

Differential Revision: D27445689

fbshipit-source-id: 2b19692e1cb822ab6785efcc5f93ee33e7dce1e5
2021-03-31 18:21:47 -07:00
Joshua Gross a0dcc4c51c Pressability: don't report touch telemetry events when the event doesn't have timestamp associated
Summary:
On iOS, not all touch events have timestamp associated. Don't report telemetry events for those events.

Separately, we can try to ensure that all iOS events have timestamps associated but it's low-pri.

Changelog: [Internal]

Reviewed By: mdvacca

Differential Revision: D27179814

fbshipit-source-id: ea2745df560bc4e9e6744bdf8f54269223adb209
2021-03-19 10:09:34 -07:00
Joshua Gross c4c0065b00 Add PressabilityPerformanceEventEmitter
Summary:
Add PressabilityPerformanceEventEmitter which allows product code / infrastructure to subscribe to touch-related performance events.

Changelog: [Added][JS] Product/infra can subscribe to Pressability touch events for telemetry purposes

Reviewed By: fkgozali

Differential Revision: D27034835

fbshipit-source-id: e62811f641994b9eadb5cdd7391e806b6cce479a
2021-03-15 23:45:45 -07:00
Kacie Bawiec 1c7d9c8046 Fix disabled prop not disabling onPress for voice assistant
Summary:
It is currently possible to activate a disabled Pressable with VoiceOver/TalkBack. This fixes this.

Changelog:
[General][Fixed] Fix disabled prop not disabling onPress for voice assistant

Reviewed By: blavalla

Differential Revision: D26225448

fbshipit-source-id: 67fa10f9e5c50143d986dc709a2fb639fdc3e718
2021-02-08 15:18:50 -08:00
Micha Reiser 93377ff508 Remove "use strict" directive from ES Modules
Summary:
ES Modules implicitly enable strict mode. Adding the "use strict" directive is, therefore, not required.

This diff removes all "use strict" directives from ES modules.

Changelog:

[Internal]

Reviewed By: motiz88

Differential Revision: D26172715

fbshipit-source-id: 57957bcbb672c4c3e62b1db633cf425c1c9d6430
2021-02-02 11:12:56 -08:00
Tim Yung ef765d423c RN: Move `TOUCH_TARGET_DEBUG` to PressabilityDebug
Summary:
This is just cleanup. When I migrated components to `Pressability` instead of `Touchable`, I left `TOUCH_TARGET_DEBUG` alone to minimize moving pieces. But I had created `PressabilityDebug` as the eventual destination for this logic.

Now that `Text` is migrated away from `Touchable` (see D26106824 (f275514f27)), this cleans up the final internal reference to `Touchable`.

Changelog:
[General][Changed] - `Touchable.renderDebugView` now accepts `ColorValue` instead of `string | number`.
[General][Removed] - Removed `Touchable.TOUCH_TARGET_DEBUG` property.

Reviewed By: kacieb

Differential Revision: D26108570

fbshipit-source-id: 2694c9a9c29182ae04a77ba6c2e4406fcd5a277e
2021-01-28 14:13:43 -08:00
Pieter Vanderwerff f2052fedc2 Land suppressions for 0.142.0 release to xplat
Summary:
This change contains the suppressions for the up coming v0.142.0 Flow release.

The new suppressions are a result the following changes:
* Disallow flowing functions or inexact objects to indexed objects to improve object soundness. This can cause errors if you are passing a function or inexact objects when an indexed object is expected.
* Flow now processes imports before checking the body of a file. In some rare cases this can expose previously skipped errors due to the processing order.

Reviewed By: mroch

Differential Revision: D25820434

fbshipit-source-id: 59cc1d852ffc8cc39f0d5112ce485fb33f05c092
2021-01-07 11:33:45 -08:00
simek 7485208498 Pressability: fix typo in variable, follow event check pattern, small tweak (#30151)
Summary:
This small PR introduces the following changes to the `Pressability`:
* fixes typo in internal `isActivationTransiton` variable name
* assigns `onPressMove` to variable before check and potential usage (this is the common pattern in this file)
* utilizes destructuring assignment to simplify passing coordinates to `_touchActivatePosition`

## Changelog

[Internal] [Fixed] - Pressability: fix typo in variable, follow event check pattern, small tweak

Pull Request resolved: https://github.com/facebook/react-native/pull/30151

Test Plan: Successful `yarn test` run.

Reviewed By: kacieb

Differential Revision: D25545662

Pulled By: nadiia

fbshipit-source-id: 8d311fe21b485ee707e05dad120322b3027e686b
2020-12-15 11:50:02 -08:00
Tim Yung 9da4d87798 Pressability: Support Lazy Hook Initialization
Summary:
Changes `usePressability` so that it accepts a nullable `config` argument.

This makes it possible for a component to use `usePressability` and lazily allocate the `config` and subsequent instance of `Pressability`. This can be useful for components that are commonly allocated but seldom pressed because it lets many usages of `usePressability` avoid allocating many extraneous objects.

Changelog:
[Internal]

Reviewed By: kacieb

Differential Revision: D23708206

fbshipit-source-id: 4a5063067131ce8c957fb16c49a2045e8c0b19fa
2020-09-28 17:23:49 -07:00
Tim Yung 0c392bc405 Pressability: Consistently Fire `onPress{In,Out}` w/o `onPress`
Summary:
Currently any component using `Pressability` is quickly tapped and released (i.e. responder grant followed only by reponder release), we fire `onPressIn` and `onPressOut` immediately to ensure that any visual feedback for the interactive element is momentarily visible.

Currently, we were mistakenly skipping this logic if `onPress` was null.

This fixes it so that we fire `onPressIn` and `onPressOut` consistently, even if `onPress` is null.

Changelog:
[General][Fixed] - Pressability now consistently fires `onPressIn` and `onPressOut`, even without an `onPress`.

Reviewed By: lunaleaps

Differential Revision: D23613254

fbshipit-source-id: e316707cbb2a4814262dea4eb1ddf6e3780268d1
2020-09-10 17:04:26 -07:00
Tim Yung 86ffb9c41e Pressability: Remove Default Press Delay
Summary:
Removes the default press delay from `Pressability`, which was introduced in 0.63 and affected `Pressable`. Fixes #29376.

In a subsequent commit, I will bring it back as an `unstable_pressDelay` prop.

Changelog:
[General][Changed] - Removed default 130ms delay from Pressability and Pressable.

Reviewed By: lunaleaps

Differential Revision: D23604582

fbshipit-source-id: c21c72bf8b59fed028f5905ca4f805bb3fa79399
2020-09-10 17:04:26 -07:00
Joshua Gross 4c0d802b4f Ensure that Pressability no longer calls configured callbacks after unmount
Summary:
Previously `reset` was not doing anything about configured callbacks, and after unmount (especially in Fabric) it was possible for callbacks to be called on unmounted nodes due to race conditions.

Changelog: [Internal]

Reviewed By: lunaleaps

Differential Revision: D23041046

fbshipit-source-id: eb9ebc8e99a0d244a2033e97178bf8ede8b5c7b2
2020-08-10 16:43:49 -07:00
Rubén Norte 4409642811 Migrate large amount of modules to flow strict and strict-local
Summary:
| Group | Before | After | Change |
| Untyped | 50 | 49 | -1 |
| flow | 197 | 155 | -42 |
| flow strict-local | 226 | 185 | -41 |
| flow strict | 33 | 117 | +84

Changelog: [Changed] Improved Flow typing of multiple modules (with migrations to `flow strict` and `flow strict-local`

Reviewed By: motiz88

Differential Revision: D22549140

fbshipit-source-id: ed29415332cfce15b244ee4dea9e13d035543175
2020-07-22 09:46:16 -07:00
David Vacca dc357b859c Revert Virtual Text Press Bug workaround
Summary:
This diff reverts the workaround added as part of D21432793, now that D21432793 is released in production for FB4A / FBiOS

changelog:
[Internal]

Reviewed By: JoshuaGross

Differential Revision: D21772129

fbshipit-source-id: 3b39738cb8fc871ec85d87f347c7f0ef408ccc3e
2020-05-28 15:44:04 -07:00
Tim Yung 2c600b7c5a RN: Persist Asynchronously Consumed Events in Pressability
Summary:
There are a few places in `Pressability` where we asynchronously consume the `event` object.

Most places do not encounter any problems because the actual properties on `event` are seldom used.

Nonetheless, we should fix these gaps.

Changelog:
[General][Fixed] - Fix invalid `event` objects from `onPressOut` in certain cases

Reviewed By: rickhanlonii

Differential Revision: D21657126

fbshipit-source-id: e28d825b85d25602427beaf0bd603d22eaa5960a
2020-05-19 22:43:51 -07:00
Tim Yung 4aaf629982 Pressable: Minimum Press Duration
Summary:
When a `Pressable` has a configured (or the default) `delayPressIn` and no (or the default) `delayPressOut`, tapping very quickly can lead to intantaneous invocation of `onPressIn` and `onPressOut`. The end result is that users may never experience any intended visual press feedback.

This changes `Pressable` to accept (and be preconfigured with a default) **minimum press duration**. The minimum press duration ensures that even if the press is released before `delayPressIn` has elapsed, `onPressOut` will still wait the remaining time up to `minPressDuration` before firing.

Note that setting a non-zero `delayPressOut` is insufficient because if a user holds down on a `Pressable` for longer than `delayPressIn`, we still want `onPressOut` to fire immediately when the press is released.

Changelog:
[General][Changed] - Added `minPressDuration` to `Pressable`.

Reviewed By: TheSavior

Differential Revision: D21614708

fbshipit-source-id: 502f3d8ad6a40e7762435b6df16809c8798dd92c
2020-05-18 21:28:10 -07:00
Tim Yung d14b89bd8a RN: Workaround Fabric + Virtual Text Press Bug
Summary:
Workaround for a bug with Fabric when pressing on virtual text.

Changelog:
[Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: JoshuaGross

Differential Revision: D21432793

fbshipit-source-id: fe20eeadd5365707fb71edae7a76d374e26b4c86
2020-05-06 14:23:05 -07:00
Zack Argyle 0a67133124 Make ColorValue public in StyleSheet.js
Summary:
This diff makes the ColorValue export "official" by exporting it from StyleSheet in order to encourage its use in product code.

Changelog: Moved ColorValue export from StyleSheetTypes to StyleSheet

Reviewed By: TheSavior

Differential Revision: D21076969

fbshipit-source-id: 972ef5a1b13bd9f6b7691a279a73168e7ce9d9ab
2020-04-17 13:03:47 -07:00
Michael Bolin 0b9ea60b4f Back out "Upgrade Prettier from 1.17 to 2.0.2."
Differential Revision: D20639755

fbshipit-source-id: 5028563f9cf0527a30b4259daac50cdc03934bfd
2020-03-24 21:47:35 -07:00
Michael Bolin cf44650b3f Upgrade Prettier from 1.17 to 2.0.2.
Summary:
This gets us on the latest Prettier 2.x:
https://prettier.io/blog/2020/03/21/2.0.0.html

Notably, this adds support for TypeScript 3.8,
which introduces new syntax, such as `import type`.

Reviewed By: zertosh

Differential Revision: D20636268

fbshipit-source-id: fca5833d003804333a05ba16325bbbe0e06d6c8a
2020-03-24 20:24:47 -07:00
Nick Gerleman 161b910494 Do not explicitly include ".js" in Library imports (#28311)
Summary:
A few recent imports have explicitly added ".js" to the end of their path. This prevents Metro from resolving platform-specific JS files, e.g. "Foo.android.js" or "Foo.windows.js" instead of "Foo.js".

React Native Windows provides its own implementation of files in a few cases where stock React Native will share them between Android and iOS. We hope to reduce/eliminate these long term, but requiring explicit ".js" files currently breaks us in a couple of places where we have custom implementations.

This change is a quick regex replace of ES6 and CommonJS imports in 'Libraries/" to eliminate ".js".

## Changelog

[General] [Fixed] - Do not explicitly include ".js" in Library imports
Pull Request resolved: https://github.com/facebook/react-native/pull/28311

Test Plan: I haven't done any manual validation of this, but `flow-check` should catch any issues with this during CI.

Reviewed By: cpojer

Differential Revision: D20486466

Pulled By: TheSavior

fbshipit-source-id: 31e1ccc307967417d7d09c34c859f0b2b69eac84
2020-03-17 02:11:53 -07:00
Tim Yung 5ca1d8f260 Pressability: Fix Missing `onLongPress` Gestures
Summary:
The current implementation of `Pressability` has a bug related to `onLongPress`.

When a user starts a press gesture, we keep track of the activation position (occurs after waiting `delayPressIn` milliseconds). If the touch moves away from that position by more than 10dp, we rule out the long press gesture. This means no matter how long you hold down the press, even if you move it back to within 10dp, we will not fire `onLongPress`.

However, there is currently a bug where we never reset the cached activation position. This means that after the first press gesture, all subsequent long press gestures must start within 10dp of that first press gesture. This leads to seemingly intermittent missing long press gestures.

This fixes the bug by ensuring that whenever a press gestures is terminated (either via a cancel or release), we reset the activation position.

Changelog:
[General][Fixed] - Fixed Pressability to properly fire `onLongPress`.

Reviewed By: TheSavior

Differential Revision: D20410075

fbshipit-source-id: e4727b7a9585ce3ea39481fc13e56b6b91740c8c
2020-03-11 23:10:48 -07:00
Tim Yung fc45530ded Pressability: Restore Press In Delay
Summary:
During the development of `Pressability`, I removed the default "press in delay" in order to minimize differences between `Touchable` (as used by `TouchableWithoutFeedback`) and `Pressability`. However, it was a bug that `TouchableWithoutFeedback` zero'd out the default press delay.

This restores the original "press in delay". This will make it so that when users swipe over a pressable element in a scroll view, the scroll view will have time to cancel the touch and prevent a press in behavior (visual jank).

Changelog:
[General] [Changed] - Increase default `delayPressIn` value for `Pressability` to 130ms.

Reviewed By: TheSavior

Differential Revision: D20176152

fbshipit-source-id: 5d6481395ee501bcab20ab98cb46a6be2c423ddf
2020-03-04 11:06:48 -08:00
Tom Underhill f4de45800f PlatformColor implementations for iOS and Android (#27908)
Summary:
This Pull Request implements the PlatformColor proposal discussed at https://github.com/react-native-community/discussions-and-proposals/issues/126.   The changes include implementations for iOS and Android as well as a PlatformColorExample page in RNTester.

Every native platform has the concept of system defined colors. Instead of specifying a concrete color value the app developer can choose a system color that varies in appearance depending on a system theme settings such Light or Dark mode, accessibility settings such as a High Contrast mode, and even its context within the app such as the traits of a containing view or window.

The proposal is to add true platform color support to react-native by extending the Flow type `ColorValue` with platform specific color type information for each platform and to provide a convenience function, `PlatformColor()`, for instantiating platform specific ColorValue objects.

`PlatformColor(name [, name ...])` where `name` is a system color name on a given platform.  If `name` does not resolve to a color for any reason, the next `name` in the argument list will be resolved and so on.   If none of the names resolve, a RedBox error occurs.  This allows a latest platform color to be used, but if running on an older platform it will fallback to a previous version.
 The function returns a `ColorValue`.

On iOS the values of `name` is one of the iOS [UI Element](https://developer.apple.com/documentation/uikit/uicolor/ui_element_colors) or [Standard Color](https://developer.apple.com/documentation/uikit/uicolor/standard_colors) names such as `labelColor` or `systemFillColor`.

On Android the `name` values are the same [app resource](https://developer.android.com/guide/topics/resources/providing-resources) path strings that can be expressed in XML:
XML Resource:
`@ [<package_name>:]<resource_type>/<resource_name>`
Style reference from current theme:
`?[<package_name>:][<resource_type>/]<resource_name>`
For example:
- `?android:colorError`
- `?android:attr/colorError`
- `?attr/colorPrimary`
- `?colorPrimaryDark`
- `android:color/holo_purple`
- `color/catalyst_redbox_background`

On iOS another type of system dynamic color can be created using the `IOSDynamicColor({dark: <color>, light:<color>})` method.   The arguments are a tuple containing custom colors for light and dark themes. Such dynamic colors are useful for branding colors or other app specific colors that still respond automatically to system setting changes.

Example: `<View style={{ backgroundColor: IOSDynamicColor({light: 'black', dark: 'white'}) }}/>`

Other platforms could create platform specific functions similar to `IOSDynamicColor` per the needs of those platforms.   For example, macOS has a similar dynamic color type that could be implemented via a `MacDynamicColor`.   On Windows custom brushes that tint or otherwise modify a system brush could be created using a platform specific method.

## Changelog

[General] [Added] - Added PlatformColor implementations for iOS and Android
Pull Request resolved: https://github.com/facebook/react-native/pull/27908

Test Plan:
The changes have been tested using the RNTester test app for iOS and Android.   On iOS a set of XCTestCase's were added to the Unit Tests.

<img width="924" alt="PlatformColor-ios-android" src="https://user-images.githubusercontent.com/30053638/73472497-ff183a80-433f-11ea-90d8-2b04338bbe79.png">

In addition `PlatformColor` support has been added to other out-of-tree platforms such as macOS and Windows has been implemented using these changes:

react-native for macOS branch: https://github.com/microsoft/react-native/compare/master...tom-un:tomun/platformcolors

react-native for Windows branch: https://github.com/microsoft/react-native-windows/compare/master...tom-un:tomun/platformcolors

iOS
|Light|Dark|
|{F229354502}|{F229354515}|

Android
|Light|Dark|
|{F230114392}|{F230114490}|

{F230122700}

Reviewed By: hramos

Differential Revision: D19837753

Pulled By: TheSavior

fbshipit-source-id: 82ca70d40802f3b24591bfd4b94b61f3c38ba829
2020-03-02 15:12:09 -08:00
Eli White 9cc920be2f Pressability: Support Rect or Numeric Size
Summary:
Introduces `Rect`, an (eventual) replacement for `EdgeInsetsProp`.

This new type is then used in `Pressability` to expand support such that `hitSlop` and `pressRectOffset` can be either a `Rect` or a numeric size.

Changelog:
[Internal]

Reviewed By: yungsters

Differential Revision: D18742616

fbshipit-source-id: 13dd360f68ab804839938fc950fa2f4b25d3ed8c
2020-01-28 15:14:23 -08:00
Eli White 4bbbe6a5ba Pressability: Create `usePressability` Hook
Summary:
Creates `usePressability`, a hook to simplify using `Pressability` from functional components.

Changelog:
[Internal]

Reviewed By: yungsters

Differential Revision: D18742613

fbshipit-source-id: 55cf48ad60a16a6a5c2c3fa2785f61f784a46b45
2020-01-28 15:14:23 -08:00
Eli White 4e31fbd39c Pressable: Update ReactTestTools to be able to tab on Pressable
Summary:
This was all yungsters idea. I blame him. :)

Switching Pressable to be a functional component presents a new challenge. ReactNativeTestTools can no longer find its instance because there is no instance Pressable uses forwardRef.

We need a way to both find a pressable, and then call the onPress callback if the pressable isn't also disabled.

So in DEV (and thus test) we add the pressable config to a secret key on a function passed onto View. The TestTools look for this key on this function, and then can call onPress.

Super hacky, but so is all of ReactNativeTestTools. We aren't proud of this.

Changelog:
[General][Changed]: Added support for Pressable to ReactNativeTestTools.tap

Reviewed By: yungsters

Differential Revision: D18849358

fbshipit-source-id: ea8880ceedfc04cda217ee17ba140475d003172c
2020-01-28 15:14:23 -08:00
Tim Yung 9b81232ed2 Pressability: Explicitly Commit Configurations
Summary:
Refactors `Pressability` so that updates to the configuration are now explicitly committed using `configure()`.

Previously, the configuration was updated implicitly because `Pressability` accepted a series of functions whose closures capture values (e.g. `this.props`). Although these changes typically happen when component instances are "atomically" updated by React, it is not a guarantee. For example, arbitrary instance variables could be used to configure `Pressability`, and they could be muted at any time.

This change makes updates to the configuration of `Pressability` more predictable.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D18742620

fbshipit-source-id: d2e96dd1e3643289daab2177199a29f80d17b0bc
2019-12-15 22:07:47 -08:00
Eli White c24c8a039c Core files should depend on internals directly
Summary:
By depending on react-native, these files can't be flow strict until index.js is flow strict. By depending on the internals directly they can be flow strict as soon as their dependents are flow strict.

Changelog:
[Internal] Refactoring some core file imports to depend on internals directly

Reviewed By: zackargyle

Differential Revision: D18828324

fbshipit-source-id: 2a347c4e234a64edbb3e6f0ef6387ef1ce78badc
2019-12-05 13:33:58 -08:00
Isabel B d3980dceab moved normalizeColor and changed dependencies (#27372)
Summary:
Originally, normalizeColor.js was in Library/Color/ however, I noticed that its tests were in a completely different directly (Library/StyleSheet/__tests__) which was confusing. The other files such as processColor.js, setNormalizedAlphaColor.js had their tests in Library/StyleSheet/__tests__ as well.

## Changelog

[Internal] [Changed] - Moved normalizeColor.js to a more appropriate directory where its tests live.
Pull Request resolved: https://github.com/facebook/react-native/pull/27372

Test Plan: I simply moved a file and changed dependencies. The code should still function as is.

Reviewed By: rickhanlonii, mdvacca

Differential Revision: D18760210

Pulled By: yungsters

fbshipit-source-id: 4c2400acabab35ccbb2533faa5c1d6487c9bf48e
2019-12-03 16:05:22 -08:00
Tim Yung c5cc181c7e RN: Open Source `Pressability`
Summary:
Makes `Pressability` available the open source `react-native` repository.

This abstraction is intended to replace `Touchable.Mixin` and enable us to finally stop depending on `createReactClass` (et al).

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D18715853

fbshipit-source-id: 21af8652cfb4557c60babd31b2776bcaeaed8447
2019-11-27 07:48:38 -08:00