Skip to content

Commit 83e1981

Browse files
huntiefacebook-github-bot
authored andcommitted
Deprecate StyleSheet.absoluteFillObject (facebook#53530)
Summary: Pull Request resolved: facebook#53530 Deprecate the `StyleSheet.absoluteFillObject` API in favour of `StyleSheet.absoluteFill` (functionally identical). Secondly, refine the type definitions in our source code (and Strict TS API) from `any` → `AbsoluteFillStyle` — resolves facebook#53470. This will be followed with updates to our docs. Changelog: [General][Deprecated] - `StyleSheet.absoluteFillObject` is deprecated in favor of `StyleSheet.absoluteFill` (equivalent). Reviewed By: yungsters Differential Revision: D81327548 fbshipit-source-id: 2bcf14694dc1bd959419629ce717760086b80ec3
1 parent e30f34e commit 83e1981

4 files changed

Lines changed: 32 additions & 58 deletions

File tree

packages/react-native/Libraries/StyleSheet/StyleSheet.d.ts

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,7 @@ export interface StyleSheetProperties {
1717
type Falsy = undefined | null | false | '';
1818
interface RecursiveArray<T>
1919
extends Array<T | ReadonlyArray<T> | RecursiveArray<T>> {}
20-
/** Keep a brand of 'T' so that calls to `StyleSheet.flatten` can take `RegisteredStyle<T>` and return `T`. */
21-
type RegisteredStyle<T> = number & {__registeredStyleBrand: T};
22-
export type StyleProp<T> =
23-
| T
24-
| RegisteredStyle<T>
25-
| RecursiveArray<T | RegisteredStyle<T> | Falsy>
26-
| Falsy;
20+
export type StyleProp<T> = T | RecursiveArray<T | Falsy> | Falsy;
2721

2822
type OpaqueColorValue = symbol & {__TYPE__: 'Color'};
2923
export type ColorValue = string | OpaqueColorValue;
@@ -127,24 +121,15 @@ export namespace StyleSheet {
127121
bottom: 0;
128122
}
129123

130-
/**
131-
* Sometimes you may want `absoluteFill` but with a couple tweaks - `absoluteFillObject` can be
132-
* used to create a customized entry in a `StyleSheet`, e.g.:
133-
*
134-
* const styles = StyleSheet.create({
135-
* wrapper: {
136-
* ...StyleSheet.absoluteFillObject,
137-
* top: 10,
138-
* backgroundColor: 'transparent',
139-
* },
140-
* });
141-
*/
142-
export const absoluteFillObject: AbsoluteFillStyle;
143-
144124
/**
145125
* A very common pattern is to create overlays with position absolute and zero positioning,
146126
* so `absoluteFill` can be used for convenience and to reduce duplication of these repeated
147127
* styles.
148128
*/
149-
export const absoluteFill: RegisteredStyle<AbsoluteFillStyle>;
129+
export const absoluteFill: AbsoluteFillStyle;
130+
131+
/**
132+
* @deprecated Use `StyleSheet.absoluteFill`.
133+
*/
134+
export const absoluteFillObject: AbsoluteFillStyle;
150135
}

packages/react-native/Libraries/StyleSheet/StyleSheetExports.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ if (hairlineWidth === 0) {
2424
hairlineWidth = 1 / PixelRatio.get();
2525
}
2626

27-
const absoluteFill: {
28-
+bottom: 0,
29-
+left: 0,
30-
+position: 'absolute',
31-
+right: 0,
32-
+top: 0,
33-
} = {
27+
const absoluteFill = {
3428
position: 'absolute',
3529
left: 0,
3630
right: 0,
@@ -108,7 +102,7 @@ export default {
108102
* so `absoluteFill` can be used for convenience and to reduce duplication of these repeated
109103
* styles.
110104
*/
111-
absoluteFill: (absoluteFill: any), // TODO: This should be updated after we fix downstream Flow sites.
105+
absoluteFill,
112106

113107
/**
114108
* Sometimes you may want `absoluteFill` but with a couple tweaks - `absoluteFillObject` can be

packages/react-native/Libraries/StyleSheet/StyleSheetExports.js.flow

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,14 @@ import type {____Styles_Internal} from './StyleSheetTypes';
1313
import composeStyles from '../../src/private/styles/composeStyles';
1414
import flattenStyle from './flattenStyle';
1515

16+
type AbsoluteFillStyle = $ReadOnly<{
17+
position: 'absolute',
18+
left: 0,
19+
right: 0,
20+
top: 0,
21+
bottom: 0,
22+
}>;
23+
1624
/**
1725
* This is defined as the width of a thin line on the platform. It can be
1826
* used as the thickness of a border or division between two elements.
@@ -37,27 +45,12 @@ declare export const hairlineWidth: number;
3745
* so `absoluteFill` can be used for convenience and to reduce duplication of these repeated
3846
* styles.
3947
*/
40-
declare export const absoluteFill: any;
48+
declare export const absoluteFill: AbsoluteFillStyle;
4149

4250
/**
43-
* Sometimes you may want `absoluteFill` but with a couple tweaks - `absoluteFillObject` can be
44-
* used to create a customized entry in a `StyleSheet`, e.g.:
45-
*
46-
* const styles = StyleSheet.create({
47-
* wrapper: {
48-
* ...StyleSheet.absoluteFillObject,
49-
* top: 10,
50-
* backgroundColor: 'transparent',
51-
* },
52-
* });
51+
* @deprecated Use `StyleSheet.absoluteFill`.
5352
*/
54-
declare export const absoluteFillObject: {
55-
+bottom: 0,
56-
+left: 0,
57-
+position: 'absolute',
58-
+right: 0,
59-
+top: 0,
60-
};
53+
declare export const absoluteFillObject: AbsoluteFillStyle;
6154

6255
/**
6356
* Combines two styles such that style2 will override any styles in style1.

packages/react-native/ReactNativeApi.d.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<0170bc4ced1f6d3d4092d837027cd391>>
7+
* @generated SignedSource<<f1e4b96664dc09f71aefe6f699a7e299>>
88
*
99
* This file was generated by scripts/js-api/build-types/index.js.
1010
*/
@@ -94,14 +94,8 @@ declare const $$ScrollViewNativeComponent: typeof ScrollViewNativeComponent_defa
9494
declare const $$SwitchNativeComponent: ComponentType
9595
declare const $$TextInlineImageNativeComponent: typeof TextInlineImage_default
9696
declare const $$ViewNativeComponent: typeof ViewNativeComponent_default
97-
declare const absoluteFill: any
98-
declare const absoluteFillObject: {
99-
readonly bottom: 0
100-
readonly left: 0
101-
readonly position: "absolute"
102-
readonly right: 0
103-
readonly top: 0
104-
}
97+
declare const absoluteFill: AbsoluteFillStyle
98+
declare const absoluteFillObject: AbsoluteFillStyle
10599
declare const AccessibilityInfo: typeof AccessibilityInfo_default
106100
declare const AccessibilityInfo_default: {
107101
addEventListener<K extends keyof AccessibilityEventDefinitions>(
@@ -1033,6 +1027,13 @@ declare type $$TextInlineImageNativeComponent =
10331027
declare type $$ViewNativeComponent = typeof $$ViewNativeComponent
10341028
declare type absoluteFill = typeof absoluteFill
10351029
declare type absoluteFillObject = typeof absoluteFillObject
1030+
declare type AbsoluteFillStyle = {
1031+
readonly bottom: 0
1032+
readonly left: 0
1033+
readonly position: "absolute"
1034+
readonly right: 0
1035+
readonly top: 0
1036+
}
10361037
declare type AbstractImageAndroid = (
10371038
props: ImageProps & {
10381039
ref?: React.Ref<
@@ -4986,6 +4987,7 @@ declare type StyleProp<T> =
49864987
| void
49874988
declare namespace StyleSheet {
49884989
export {
4990+
AbsoluteFillStyle,
49894991
hairlineWidth,
49904992
absoluteFill,
49914993
absoluteFillObject,
@@ -6167,7 +6169,7 @@ export {
61676169
StatusBarProps, // 06c98add
61686170
StatusBarStyle, // 986b2051
61696171
StyleProp, // fa0e9b4a
6170-
StyleSheet, // 02b98c20
6172+
StyleSheet, // 366689d4
61716173
SubmitBehavior, // c4ddf490
61726174
Switch, // aebc9941
61736175
SwitchChangeEvent, // 2e5bd2de

0 commit comments

Comments
 (0)