Skip to content

Commit

Permalink
Require all Android View Attributes are defined in flow prop types
Browse files Browse the repository at this point in the history
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
  • Loading branch information
elicwhite authored and aleclarson committed Sep 16, 2018
1 parent c85bc74 commit 64ea811
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
11 changes: 10 additions & 1 deletion Libraries/Components/View/ViewNativeComponentAndroidConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,18 @@ const ReactNativeStyleAttributes = require('ReactNativeStyleAttributes');

const processColor = require('processColor');

import type {ViewProps} from 'ViewPropTypes';
import type {____ViewStyle_Internal} from 'StyleSheetTypes';
import type {ReactNativeBaseComponentViewConfig} from 'ReactNativeTypes';

const colorHandler = {diff: null, process: processColor};

const ViewNativeComponentAndroidConfig = {
type Config = ReactNativeBaseComponentViewConfig<
$Keys<ViewProps> | $Keys<____ViewStyle_Internal>,
$Keys<____ViewStyle_Internal>,
>;

const ViewNativeComponentAndroidConfig: Config = {
bubblingEventTypes: {
topChange: {
phasedRegistrationNames: {
Expand Down
17 changes: 17 additions & 0 deletions Libraries/Components/View/ViewPropTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,27 @@ type GestureResponderEventProps = $ReadOnly<{|
onStartShouldSetResponderCapture?: ?Function,
|}>;

type AndroidViewProps = $ReadOnly<{|
nativeBackgroundAndroid?: ?Object,
nativeForegroundAndroid?: ?Object,

/* Deprecated transform prop. Use the transform style prop instead */
rotation?: empty,
/* Deprecated transform prop. Use the transform style prop instead */
scaleX?: empty,
/* Deprecated transform prop. Use the transform style prop instead */
scaleY?: empty,
/* Deprecated transform prop. Use the transform style prop instead */
translateX?: empty,
/* Deprecated transform prop. Use the transform style prop instead */
translateY?: empty,
|}>;

export type ViewProps = $ReadOnly<{|
...DirectEventProps,
...GestureResponderEventProps,
...TouchEventProps,
...AndroidViewProps,

// There's no easy way to create a different type if (Platform.isTV):
// so we must include TVViewProps
Expand Down
11 changes: 7 additions & 4 deletions Libraries/Renderer/shims/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@ type AttributeType =
process: ?(arg1: any) => any,
|}>;

export type ReactNativeBaseComponentViewConfig = $ReadOnly<{|
export type ReactNativeBaseComponentViewConfig<
TProps = string,
TStyleProps = string,
> = $ReadOnly<{|
baseModuleName?: string,
bubblingEventTypes?: $ReadOnly<{
[eventName: string]: $ReadOnly<{|
Expand All @@ -74,14 +77,14 @@ export type ReactNativeBaseComponentViewConfig = $ReadOnly<{|
}>,
uiViewClassName: string,
validAttributes: $ReadOnly<{
[propName: string]: AttributeType,
[propName: TProps]: AttributeType,
style: $ReadOnly<{
[propName: string]: AttributeType,
[propName: TStyleProps]: AttributeType,
}>,
}>,
|}>;

export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig;
export type ViewConfigGetter = () => ReactNativeBaseComponentViewConfig<>;

/**
* Class only exists for its Flow type.
Expand Down
4 changes: 2 additions & 2 deletions Libraries/Renderer/shims/ReactNativeViewConfigRegistry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ const viewConfigCallbacks = new Map();
const viewConfigs = new Map();

function processEventTypes(
viewConfig: ReactNativeBaseComponentViewConfig,
viewConfig: ReactNativeBaseComponentViewConfig<>,
): void {
const {bubblingEventTypes, directEventTypes} = viewConfig;

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

0 comments on commit 64ea811

Please sign in to comment.