Skip to content

Commit 7b1186c

Browse files
elicwhitehramos
authored andcommitted
Require all Android View Attributes are defined in flow prop types
Summary: This caught a few flow types that weren't defined for attributes that Android exposes. Ensuring that these stay in sync will be necessary for codegen in the future. Reviewed By: sahrens Differential Revision: D9444165 fbshipit-source-id: 8ee00af7b732c35d7f6befcdf79f77b73eac6a1b
1 parent 3ccc141 commit 7b1186c

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

Libraries/Components/View/ViewNativeComponentAndroidConfig.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,18 @@ const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');
1414

1515
const processColor = require('processColor');
1616

17+
import type {ViewProps} from 'ViewPropTypes';
18+
import type {____ViewStyle_Internal} from 'StyleSheetTypes';
19+
import type {ReactNativeBaseComponentViewConfig} from 'ReactNativeTypes';
20+
1721
const colorHandler = {diff: null, process: processColor};
1822

19-
const ViewNativeComponentAndroidConfig = {
23+
type Config = ReactNativeBaseComponentViewConfig<
24+
$Keys<ViewProps> | $Keys<____ViewStyle_Internal>,
25+
$Keys<____ViewStyle_Internal>,
26+
>;
27+
28+
const ViewNativeComponentAndroidConfig: Config = {
2029
bubblingEventTypes: {
2130
topChange: {
2231
phasedRegistrationNames: {

Libraries/Components/View/ViewPropTypes.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,27 @@ type GestureResponderEventProps = $ReadOnly<{|
7171
onStartShouldSetResponderCapture?: ?Function,
7272
|}>;
7373

74+
type AndroidViewProps = $ReadOnly<{|
75+
nativeBackgroundAndroid?: ?Object,
76+
nativeForegroundAndroid?: ?Object,
77+
78+
/* Deprecated transform prop. Use the transform style prop instead */
79+
rotation?: empty,
80+
/* Deprecated transform prop. Use the transform style prop instead */
81+
scaleX?: empty,
82+
/* Deprecated transform prop. Use the transform style prop instead */
83+
scaleY?: empty,
84+
/* Deprecated transform prop. Use the transform style prop instead */
85+
translateX?: empty,
86+
/* Deprecated transform prop. Use the transform style prop instead */
87+
translateY?: empty,
88+
|}>;
89+
7490
export type ViewProps = $ReadOnly<{|
7591
...DirectEventProps,
7692
...GestureResponderEventProps,
7793
...TouchEventProps,
94+
...AndroidViewProps,
7895

7996
// There's no easy way to create a different type if (Platform.isTV):
8097
// so we must include TVViewProps

Libraries/Renderer/shims/ReactNativeTypes.js

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,10 @@ type AttributeType =
5151
process: ?(arg1: any) => any,
5252
|}>;
5353

54-
export type ReactNativeBaseComponentViewConfig = $ReadOnly<{|
54+
export type ReactNativeBaseComponentViewConfig<
55+
TProps = string,
56+
TStyleProps = string,
57+
> = $ReadOnly<{|
5558
baseModuleName?: string,
5659
bubblingEventTypes?: $ReadOnly<{
5760
[eventName: string]: $ReadOnly<{|
@@ -74,14 +77,14 @@ export type ReactNativeBaseComponentViewConfig = $ReadOnly<{|
7477
}>,
7578
uiViewClassName: string,
7679
validAttributes: $ReadOnly<{
77-
[propName: string]: AttributeType,
80+
[propName: TProps]: AttributeType,
7881
style: $ReadOnly<{
79-
[propName: string]: AttributeType,
82+
[propName: TStyleProps]: AttributeType,
8083
}>,
8184
}>,
8285
|}>;
8386

84-
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
87+
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>;
8588

8689
/**
8790
* Class only exists for its Flow type.

Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const viewConfigCallbacks = new Map();
3030
const viewConfigs = new Map();
3131

3232
function processEventTypes(
33-
viewConfig: ReactNativeBaseComponentViewConfig,
33+
viewConfig: ReactNativeBaseComponentViewConfig<>,
3434
): void {
3535
const {bubblingEventTypes, directEventTypes} = viewConfig;
3636

@@ -86,7 +86,7 @@ exports.register = function(name: string, callback: ViewConfigGetter): string {
8686
* If this is the first time the view has been used,
8787
* This configuration will be lazy-loaded from UIManager.
8888
*/
89-
exports.get = function(name: string): ReactNativeBaseComponentViewConfig {
89+
exports.get = function(name: string): ReactNativeBaseComponentViewConfig<> {
9090
let viewConfig;
9191
if (!viewConfigs.has(name)) {
9292
const callback = viewConfigCallbacks.get(name);

0 commit comments

Comments
 (0)