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

253 Коммитов

Автор SHA1 Сообщение Дата
Marshall Roch 309d705e6a Deploy 0.178.0 to xplat
Summary: Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D36356453

fbshipit-source-id: e56e4694d4e0811f760a3994a889b48f2ba8cffb
2022-05-12 20:06:24 -07:00
George Zahariev 0337a2981d Add annotations to empty objects that look like indexers in Xplat
Summary:
We are working on making the empty object literal `{}` have the type `{}` - i.e. exact empty object - rather than being unsealed.
Making this change exposes a variety of errors. We can prevent these errors by annotating what we want the type of the empty object to be.

Reduces Xplat error diff to 2.3k

- Announcement: [post](https://fb.workplace.com/groups/flowlang/posts/903386663600331)
- Support group: [Flow Support](https://fb.workplace.com/groups/flow)

drop-conflicts

Format:
```
arc f
```
Sort imports
```
hg l -n | xargs js1 lint --fix --rule 'fb-tools/sort-requires'
```

Changelog: [Internal]

Reviewed By: samwgoldman

Differential Revision: D36086696

fbshipit-source-id: 90447279f2e6e38f44189b74ec0297719f7adf58
2022-05-03 19:59:28 -07:00
Moti Zilberman 370c65b943 Refactor StyleSheetTypes for (internal) extensibility
Summary: Changelog: [Internal]

Reviewed By: arushikesarwani94

Differential Revision: D34188705

fbshipit-source-id: 017285553f24144f8f7eff3a126a99be6c9b2f25
2022-02-15 08:50:55 -08:00
Moti Zilberman 83b1975b90 Extend ColorValue Flow type to include numbers
Summary:
Adds `number` to the `ColorValue` union type.

Per our docs, React Native supports specifying colours as RGBA values packed into ints: https://reactnative.dev/docs/colors#color-ints. It looks like this case was missed in D6226807 (da047966e4) when we started typing the `StyleSheet` API with Flow.

Changelog: [General][Fixed] - Support numeric color values in StyleSheet's Flow types

Reviewed By: yungsters

Differential Revision: D34140748

fbshipit-source-id: 5bfe2995a473260926fa3c8b6926bb841615d393
2022-02-11 06:54:24 -08:00
Moti Zilberman 159eb0bdf4 Normalize platform colors early
Summary:
Changelog: [Internal]

Fixes `normalizeColor` to always return the normalized color. Previously, when normalization was delegated to `normalizeColorObject`, we would return the *original* color object, which is a bug.

Reviewed By: javache

Differential Revision: D34048595

fbshipit-source-id: 083cbe36be2311ea9cffe8ef61e6a986840aec71
2022-02-10 04:57:47 -08:00
Pieter De Baets d682753244 Support setting hitSlop with single value (JS) [re-land]
Summary:
JS changes to support D32138347 (a96bdb7154). This was previously reverted due to missing iOS Paper support.

Changelog: [Android][Fixed] Enable hitSlop to be set using a single number.

Original commit changeset: 91cfcc86582c

Original Phabricator Diff: D32559015 (589b129581)

Reviewed By: yungsters

Differential Revision: D33453327

fbshipit-source-id: d289a0a8b8208bc9c68e6ca537632b745e8196ed
2022-01-31 04:06:22 -08:00
Pieter De Baets 78614de1cb Revert D32559015: Support setting hitSlop with single value (JS changes)
Differential Revision:
D32559015 (589b129581)

Original commit changeset: c0409e6e5dd9

Original Phabricator Diff: D32559015 (589b129581)

fbshipit-source-id: 91cfcc86582c4716fc531a73bd8e06dea1406abd
2022-01-05 14:06:54 -08:00
Pieter De Baets 589b129581 Support setting hitSlop with single value (JS changes)
Summary:
JS changes to support D32138347 (a96bdb7154)

Changelog: [Android][Fixed] Enable hitSlop to be set using a single number.

Reviewed By: yungsters

Differential Revision: D32559015

fbshipit-source-id: c0409e6e5dd95b35a2a4605b16cfb48104be2858
2022-01-04 10:39:43 -08:00
Andres Suarez 8bd3edec88 Update copyright headers from Facebook to Meta
Reviewed By: aaronabramov

Differential Revision: D33367752

fbshipit-source-id: 4ce94d184485e5ee0a62cf67ad2d3ba16e285c8f
2021-12-30 15:11:21 -08:00
Evan Yeung 037e346197 Add LTI annotations to xplat/js
Summary:
This diff runs the codemod to add type annotations to function parameters in preparation for Flow's local type inference (LTI) project. I ran the codemod over xplat/js and reverted any files that had flow errors in them. See the list of commands run to see the regeneration of various files.

Changelog:
[Internal][Changed] - Added type annotations

Reviewed By: yungsters

Differential Revision: D32075270

fbshipit-source-id: 6a9cd85aab120b4d9e690bac142a415525dbf298
2021-11-10 15:40:15 -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
Tim Yung 65e58f26e1 RN: @react-native/normalize-color support Node.js
Summary:
Changes `react-native/normalize-color` to be useable from Node.js by making the following changes:

1. Rename `base.js` to `index.js` so importing is more convenient.
2. Move Flow definitions into a seprate library definition flow so `index.js` can be consumed directly.

I also made a few improvements to the actual implementation:

1. Avoid allocating `matchers` for non-strings.
2. Avoid allocating an object of all the color keywords. This will reduce memory usage (in exchange for slightly larger compiled bytecode).

Changelog:
[General][Changed] - react-native/normalize-color now supports Node.js

Reviewed By: lunaleaps

Differential Revision: D30595908

fbshipit-source-id: e6279e9ff815d8d1f489811187deabfdf53b8fbf
2021-09-01 01:26:56 -07:00
Tim Yung 33b385825c RN: Simplify `ReactNativeStyleAttributes` Type
Summary:
Simplifies the Flow type for `ReactNativeStyleAttributes`, an internal module.

Changelog:
[Internal]

Reviewed By: TheSavior

Differential Revision: D29019311

fbshipit-source-id: cf95dac4b8c2261812cc1d753255dfb905540759
2021-06-11 23:52:09 -07:00
Tim Yung 2e8c0bd7ea RN: Delete `StyleSheetValidation`
Summary:
Deletes `StyleSheetValidation` because it is `prop-types` in disguise.

Changelog:
[General][Removed] - `StyleSheet.create` will no longer do DEV-time validation.

Reviewed By: TheSavior

Differential Revision: D29019310

fbshipit-source-id: bfe886d8dc09a1aa8dac4a73bfd62f481e3eb9e9
2021-06-11 23:52:09 -07:00
Birkir Gudjonsson 4b9d9dda27 Accessible colors for DynamicColorIOS (#31651)
Summary:
Allow you to harvest the `UIAccessibilityContrastHigh` trait from iOS to show accessible colors when high contrast mode is enabled.

```jsx
// usage

PlatformColorIOS({
  light: '#eeeeee',
  dark: '#333333',
  highContrastLight: '#ffffff',
  highContrastDark: '#000000',
});

// {
//   "dynamic": {
//     "light": "#eeeeee",
//     "dark": "#333333",
//     "highContrastLight": "#ffffff",
//     "highContrastDark": "#000000",
//   }
// }
```

This is how apple's own dynamic system colors work under the hood (https://developer.apple.com/design/human-interface-guidelines/ios/visual-design/color/#dynamic-system-colors)

 ---

The react native docs mention that more keys may become available in the future, which this PR is adding:

> In the future, more keys might become available for different user preferences, like high contrast.

https://reactnative.dev/docs/dynamiccolorios

## 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
-->

[iOS] [Added] - High contrast dynamic color options for dark and light mode.

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

Test Plan: Added unit tests for `normalizeColor` to pass the high contrast colors downstream to RCTConvert

Reviewed By: lunaleaps

Differential Revision: D28922536

Pulled By: p-sun

fbshipit-source-id: f81417f003c3adefac50e994e62b9be14ffa91a1
2021-06-08 11:51:23 -07:00
Tim Yung bb6cd56fae RN: Fallback for Invalid Colors in `processColorArray`
Summary:
If an invalid color is supplied to a native component that expects `Array<ColorValue>`, it is currently possible to produce an array that contains null or undefined elements. This is problematic because the native component may not know what to do with the null or undefined value.

This changes `processColorArray` to always return an array with valid color values. Any invalid color values will fallback to being transparent black, `0x00000000`.

Changelog:
[General][Fixed] - For native components that accept color arrays, invalid elements will now fallback to transparent with a console error.

Reviewed By: JoshuaGross

Differential Revision: D27542291

fbshipit-source-id: efa5d130644b3aee68d2b9fad6fdb61af11a2966
2021-04-02 15:07:54 -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
Luna Wei 321de15803 Delete unused FlowFixMes in xplat/js/react-native-github
Summary:
Changelog:
[Internal] - Remove unused FlowFixMes

Reviewed By: kacieb

Differential Revision: D27445690

fbshipit-source-id: c1fbf4495ae020b30a458c2ef4870547fd5d5c6e
2021-03-31 18:21:47 -07: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
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
Tim Yung 54a067e61e RN: Refactor `ScrollView` Style Splitting
Summary:
Rewrites `splitLayoutProps`, which is only used by `ScrollView`.

- Improve type safety by avoiding `DangerouslyImpreciseStyle`.
- Avoid allocating objects when it is not necessary.
- Avoid allocating a object enumeratig layout props by using a switch statement.

Changelog:
[Internal]

Reviewed By: JoshuaGross, kacieb

Differential Revision: D25097226

fbshipit-source-id: 2050c03b681024212c06a48b7eb05f28c14415f9
2020-11-19 15:55:23 -08:00
Tim Yung 7e7527e7db RN: Preserve Style Type in `flattenStyle`
Summary:
Refactors `flattenStyle` so that it preserves the style type of the argument. This lets us avoid using `DangerouslyImpreciseStyleProp` where we can.

Changelog:
[Internal]

Reviewed By: JoshuaGross, nadiia, kacieb

Differential Revision: D25097227

fbshipit-source-id: df6af6fefab25dbb62e3c81897c3cef98619a9c7
2020-11-19 15:55:23 -08:00
Panagiotis Vekris 254d455103 Add type annotations to prevent issues with planned Flow changes
Summary:
We're planning a fix in Flow (D24112595) that uncovers some existing errors that were
previously suppressed. Adding these annotations prevents them from surfacing during the
deploy of the fix.

Changelog: [Internal]

Reviewed By: dsainati1

Differential Revision: D24147994

fbshipit-source-id: fef59a9427da6db79d4824e39768dd5ad0a8d1a3
2020-10-09 15:52:21 -07:00
Tim Yung 9c9e677918 RN: Remove `react-animated` Legacy Package
Summary:
Removes the legacy `react-animated` package configuration and collapses the `Animated/src/` directory into `Animated/`.

Also, reconfigures all references to `Animated/src/` to just be `Animated/`.

Changelog:
[Internal]

Reviewed By: cpojer

Differential Revision: D22450848

fbshipit-source-id: 9fd4861e9f357d817d82e9fec71967a2936a3830
2020-08-25 14:15:35 -07:00
Christoph Nakazawa ab56ed7d96 Create `@react-native/normalize-color` package
Summary: Changelog: [Internal]

Reviewed By: TheSavior

Differential Revision: D22644750

fbshipit-source-id: f1b24c7e72819650517b7b42f93eeeed9c1e627b
2020-07-24 08:36:37 -07:00
Hein Rutjes cfa4260598 Add support for shadowColor on Android (API >= 28) (#28650)
Summary:
This PR adds support for the `shadowColor` style on Android.

This is possible as of Android P using the `setOutlineAmbientShadowColor` and `setOutlineSpotShadowColor` View methods. The actual rendered color is a multiplication of the color-alpha, shadow-effect and elevation-value.

## Changelog

`[Android] [Added] - Add support for shadowColor on API level >= 28`
Pull Request resolved: https://github.com/facebook/react-native/pull/28650

Test Plan:
- Only execute code on Android P
- Added Android `BoxShadow` tests to RNTester app

![image](https://user-images.githubusercontent.com/6184593/79457137-fe627c80-7fef-11ea-8e88-3d9423a4f264.png)

Reviewed By: mdvacca

Differential Revision: D21125479

Pulled By: shergin

fbshipit-source-id: 14dcc023977d7a9d304fabcd3c90bcf34482f137
2020-07-07 23:32:38 -07:00
Nick Gerleman e75557b48f Restore Previous Behavior for StyleSheet Validation of Null/Undefined Styles (#29171)
Summary:
https://github.com/facebook/react-native/issues/27264 changed stylesheet validation to avoid enumerating properties on the prototype of a style. It introduces a secondary behavior change, where null/undefined styles used to be tolerated but now lead to an exception. This is because `for in undefined` will noop where `for of Object.keys(undefined)` will throw.

This scenario of undefined/null styles seems to actually show up in practice and was previously well tolerated. E.g. `Button.js` has code that looks like this:

```jsx
const styles = StyleSheet.create({
  button: Platform.select({
    ios: {},
    android: {
      elevation: 4,
      // Material design blue from https://material.google.com/style/color.html#color-color-palette
      backgroundColor: '#2196F3',
      borderRadius: 2,
    },
  }),
```

For non ios/Android platforms, that creates a style object which looks like:
```js
{
  button: undefined,
  ...
}
```

This previously meant that the component would be unstyled if created, but now means out-of-tree platforms throw if the builtin Button component is required.

This change restores the previous `for in` loop but adds a `hasOwnProperty` check to avoid properties on prototypes.

## Changelog

[General] [Fixed] - Restore Previous Behavior for StyleSheet Validation of Null/Undefined Styles
Pull Request resolved: https://github.com/facebook/react-native/pull/29171

Test Plan: Validated that importing Buttons will no longer cause an exception, and that invalid properties are still caught.

Reviewed By: JoshuaGross

Differential Revision: D22118379

Pulled By: TheSavior

fbshipit-source-id: 650c64b934ccd12a3dc1b75e95debc359925ad73
2020-06-25 15:31:54 -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
Tom Underhill 411c344794 Remove ColorAndroid function as it adds no value over PlatfromColor (#28577)
Summary:
This change removes the `ColorAndroid` API.   It was added more as a validation tool than as something useful to a developer.   When making the original [PlatformColor PR](https://github.com/facebook/react-native/pull/27908) we felt it was valuable and useful to have working platform specific methods for the two platforms in core to test that the pattern worked in app code (PlatformColorExample.js in RNTester) and that the Flow validation worked, etc.    Practically `PlatformColor()` is more useful to a developer on Android than `ColorAndroid()`.    Now that the construct has served its purpose, this PR removes the `ColorAndroid` function and its related tests and other collateral.

## 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] [Removed] - Remove ColorAndroid function as it adds no value over PlatfromColor
Pull Request resolved: https://github.com/facebook/react-native/pull/28577

Test Plan: RNTester in both iOS and Android was tested.   Jest tests, Flow checks, Lint checks all pass.

Reviewed By: cpojer

Differential Revision: D20952613

Pulled By: TheSavior

fbshipit-source-id: 7d2cbaa2a347fffe59a1f3a26a210676008fdac0
2020-04-09 18:40:31 -07:00
George Zahariev cd347a7e0e Upgrade Prettier in Xplat to version 1.19.1
Summary:
Upgrades Prettier in Xplat to 1.19.1
Ignores upgrading packages on already on versions greater than 1.19.1

Changelog: [Internal]

allow-large-files
bypass-lint

(Note: this ignores all push blocking failures!)

Reviewed By: gkz, cpojer

Differential Revision: D20879147

fbshipit-source-id: 0deee7ac941e91e1c3c3a1e7d3d3ed20de1d657d
2020-04-09 11:01:58 -07:00
Tom Underhill 602070f44b Add ES Lint rules for `DynamicColorIOS()`and `ColorAndroid()` (#28398)
Summary:
The [PlatformColor PR](https://github.com/facebook/react-native/pull/27908) added support for iOS and Android to express platform specific color values.   The primary method for an app to specify such colors is via the `PlatformColor()` method that takes string arguments.   The `PlatformColor` method returns an opaque Flow type enforcing that apps use the PlatformColor method instead of creating Objects from scratch -- doing so would make it harder to write static analysis tools around Color values in the future.   But in addition to `PlatformColor()`, iOS has a `DynamicColorIOS()` method that takes an Object.   The Flow type for this Object cannot be opaque, but we still want to enforce that app code doesn't pass variables instead of Object literals or that values in the Objects are variables.   To ensure `DynamicColorIOS()` can be statically analyzed this change adds an ESLint rule to enforce that `DynamicColorIOS()` takes an Object literal of a specific shape.   A `ColorAndroid()` was also introduced not for practical use but just to test having platform specific methods for more than one platform in the same app.   A second ESLint rule is created for `ColorAndroid` as well.

## Changelog

[General] [Changed] - Add ES Lint rules for `DynamicColorIOS()`and `ColorAndroid()`
Pull Request resolved: https://github.com/facebook/react-native/pull/28398

Test Plan: `yarn lint` passes.

Reviewed By: cpojer

Differential Revision: D20685383

Pulled By: TheSavior

fbshipit-source-id: 9bb37ccc059e74282b119577df0ced63cb9b1f53
2020-03-27 23:02:15 -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
Hans Halverson 4482e531d8 Move suppressions to primary locations in xplat/js
Reviewed By: gkz

Differential Revision: D20446329

fbshipit-source-id: 2713e7713f6b0e8d1dfd9ab8c0ccb27294177589
2020-03-16 21:28:17 -07:00
Jesse Katsumata 66e7a4c1aa Fix outdated urls (#28285)
Summary:
Fixed some url in the code that was outdated.

## Changelog

[Internal] [Fixed] - Fix outdated url in Image Example of RNTester and comment in StyleSheet Type
Pull Request resolved: https://github.com/facebook/react-native/pull/28285

Test Plan: Url can be accessed, and content displayed makes sense.

Differential Revision: D20464293

Pulled By: shergin

fbshipit-source-id: f0c97f7a95ed2a3d6c396cff6cda0bdaab7f5c35
2020-03-15 22:58:14 -07:00
Riley Dulin ce1703a84d Change stringifySafe to have limits on larger objects
Summary:
In heap snapshots, it was found that really large (20 MB) strings representing network data
were being logged as part of `Systrace.beginEvent` strings from `MessageQueue` in DEV mode.

To combat this, use `JSON.stringify` with limits to keep the depth, strings, arrays, and objects
in check.

Changelog: [Internal] Change `stringifySafe` to have max limits on string size

Reviewed By: yungsters

Differential Revision: D20016501

fbshipit-source-id: e123016557bc154e4210e0b4df44360570da8016
2020-03-02 17:28:21 -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
Hans Halverson a3d9e91203 Move suppression to primary locations in xplat/js
Summary:
We will soon be enforcing that flow suppressions will only apply when on an error's primary location ([post](https://fb.workplace.com/groups/179614562644215/permalink/559286354677032/)). This diff uses the codemod created in D20008770 to move all suppression comments to their primary locations in the  `xplat/js` flow root, and deletes suppression comments that are not on any primary locations.

This diff was generated with:
```
~/fbsource/fbcode/flow/packages/flow-dev-tools/bin/tool suppression-primary-locations --json-file ~/www/errors.json  ~/fbsource/xplat/js
hg st -n | xargs grep -l -P '@(partially-)?generated' | xargs hg revert
hg st -n | xargs grep -l 'format' | xargs prettier --write
```

Changelog: [Internal]

bypass-lint

Reviewed By: dsainati1

Differential Revision: D20122544

fbshipit-source-id: d94e409aadb18bb399a1ddbf9f3f2494fe4fb54c
2020-02-27 12:14:57 -08:00
Tom Underhill dbe0d7d4b5 Add NativeColorType opaque type to normalizeColor() ahead of PlatformColor PR. (#28040)
Summary:
The [PlatformColor PR](https://github.com/facebook/react-native/pull/27908) is currently open to implement the [PlatformColor proposal](react-native-community/discussions-and-proposals#126).   When that PR was imported into Facebooks internal builds it was found that the change to the `processColor()` function to return an opaque type or `number` instead of just `number` breaks internal components.

This PR is a simplification of the PlatformColor PR only changing the return type of `processColor()` from `?number` to `?number | NativeColorType` where `NativeColorType` is just an empty but opaque type.   This will allow changes to be made to these internal components but with less risk than the larger PR.

## Changelog

[General] [Changed] - Add NativeColorType opaque type to normalizeColor() ahead of PlatformColor PR
Pull Request resolved: https://github.com/facebook/react-native/pull/28040

Test Plan: Flow checks, Jest test, iOS unit tests, iOS integration tests, and manual testing performed on RNTester for iOS and Android.

Differential Revision: D19860205

Pulled By: TheSavior

fbshipit-source-id: 799662c6621d3974158b375ccccfa136982c43b4
2020-02-19 19:33:27 -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
Nat Mote c40988cc22 Deploy Flow v0.116 to xplat
Summary: Changelog: [Internal]

Reviewed By: gkz

Differential Revision: D19416307

fbshipit-source-id: 32767f24e5bfeb1912f7dd5527eb8c4db7a08a1a
2020-01-16 14:05:49 -08:00
Jordan Brown 4e71a30969 Fix return type of StyleSheet.create to be the identity function
Summary:
Changes the return type of StyleSheet.create to `$ReadOnly<S>`. At runtime, it just freezes the fields in dev mode and is the identity function otherwise. This cause 423 errors due to the wrong props being passed to different styles: P124372727

I went over errors at random with Eli to get confidence in the change.

Changelog:
[General][Fixed] Fix return type of StyleSheet.create

Reviewed By: zackargyle, TheSavior

Differential Revision: D19218817

fbshipit-source-id: b7aa10700f8333372c9f0bd61bfbef371caadf97
2020-01-02 10:01:15 -08:00
Freeman Latif f464dad5d4 Fix stylesheet validation of functions with additional prototype methods (#27264)
Summary:
Some babel plugins add additional methods to `Function.prototype` (see https://github.com/MatAtBread/fast-async):

```js
Function.prototype.$asyncbind = function $asyncbind(self, catcher) {
...
```

Although undocumented, React Native allows functions to be passed to `StyleSheet.create()` for dynamic styling:

```js
const styles = StyleSheet.create({
  animalItem: height => ({ height })
});
```

If there are additional custom methods on `Function.prototype`, React Native's `StyleSheetValidation.validateStyle` will loop through these properties and raise an error because those properties are not valid style keys, because it loops through _all_ properties, including inherited ones.

![Simulator Screen Shot - iPhone 11 Pro Max - 2019-11-19 at 12 04 49](https://user-images.githubusercontent.com/4031216/69145112-ce589100-0ac4-11ea-80d7-e93d59b935a8.png)

This PR modifies `StyleSheetValidation.validateStyle` to only loop through the style's own properties, instead of including inherited ones.

## Changelog

[General] [Fixed] - Fix stylesheet validation for functions with custom prototype methods.
Pull Request resolved: https://github.com/facebook/react-native/pull/27264

Test Plan: - Tested that non-function style properties are still validated

Differential Revision: D18694895

Pulled By: hramos

fbshipit-source-id: b36f4a62a435e7b6a689398de3bcc06d6bb14293
2019-12-17 18:25:32 -08:00
talhaazhar 3c4b1d6c4f adding tests for the processColorArray mapping (#27344)
Summary:
The following pull-requests adds test for the `processColorArray` function. This ensures that the mapping is respected even in the `processColor` file changes. It also ensures that the mapping follows the basic expected functionality

## Changelog
[General] [Added] - Add test for the `processColorArray` to make sure it maps correctly
Pull Request resolved: https://github.com/facebook/react-native/pull/27344

Test Plan:
- Run `npm run test Libraries/StyleSheet/__tests__/processColorArray-test.js` to ensure tests pass
- Run `npm run lint` to make sure there are no styling conflicts.

<img width="454" alt="Screen Shot 2019-11-26 at 3 24 44 PM" src="https://user-images.githubusercontent.com/31664059/69680816-e8641780-1060-11ea-89ca-336c5534eb16.png">

Differential Revision: D18770069

Pulled By: hramos

fbshipit-source-id: 1a8647931818360b9912dc6fb50c339a91b9d4ea
2019-12-04 15:27:54 -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
George Zahariev 8553e1acc4 Exact-by-default codemod for react-native-github
Summary:
We are rolling out exact-by-default syntax to xplat/js.

I had to manually move around some comments to preserve proper placement.

Changelog: [Internal]

Reviewed By: jbrown215

Differential Revision: D18633611

fbshipit-source-id: 48f7468dcc55b1d00985419d035a61c6820b3abe
2019-11-21 09:42:57 -08:00
Andres Suarez 3b31e69e28 Tidy up license headers [2/n]
Summary: Changelog: [General] [Fixed] - License header cleanup

Reviewed By: yungsters

Differential Revision: D17952694

fbshipit-source-id: 17c87de7ebb271fa2ac8d00af72a4d1addef8bd0
2019-10-16 10:06:34 -07:00
Miguel Alatzar 0a282c42b4 Include transform in OUTER_PROPS (#26611)
Summary:
Without `transform` in `OUTER_PROPS`, the refresh control component would not include `transform: {scaleY: -1}` in its style and so pulling down, rather than up, on a scroll view would trigger a refresh.

Fixes https://github.com/facebook/react-native/issues/26181

## Changelog
[Android] [Fixed] - Fixed issue with refresh control not working properly on an inverted ScrollView
Pull Request resolved: https://github.com/facebook/react-native/pull/26611

Test Plan: Updated unit test in splitLayoutProps-test.js.

Differential Revision: D17661079

Pulled By: cpojer

fbshipit-source-id: 747da27b11c3ca59b7f639f393ae5ac137f5490a
2019-09-29 18:49:45 -07:00
Samuel Susla 845cbec5cf Add codegen support for EdgeInsets
Summary: Add codegen support for `EdgeInsets`.

Reviewed By: rickhanlonii

Differential Revision: D17500509

fbshipit-source-id: b2909fe296c51d3a47cc961c45294eead7707853
2019-09-23 09:12:51 -07:00