Skip to content

Commit

Permalink
Support excluding multiple platforms.
Browse files Browse the repository at this point in the history
Summary:
Currently the schema only allows to exclude a single platform (iOS OR Android). There are cases where we need to exclude multiple. This change converts the previous `excludePlatform` string property into an `excludePlatforms` array.

Changelog:
[Internal][Changed] - Added support to exclude multiple platforms in Codegen.

Reviewed By: sammy-SC

Differential Revision: D21426950

fbshipit-source-id: eff36ffa207109274794b4b300bf6313f8286161
  • Loading branch information
joaovieira authored and facebook-github-bot committed May 7, 2020
1 parent 7bb1c4e commit 16ea9ba
Show file tree
Hide file tree
Showing 31 changed files with 499 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,5 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

export default (codegenNativeComponent<NativeProps>('DatePicker', {
paperComponentName: 'RCTDatePicker',
excludedPlatform: 'android',
excludedPlatforms: ['android'],
}): HostComponent<NativeProps>);
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,5 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

export default (codegenNativeComponent<NativeProps>('PullToRefreshView', {
paperComponentName: 'RCTRefreshControl',
excludedPlatform: 'android',
excludedPlatforms: ['android'],
}): HostComponent<NativeProps>);
2 changes: 1 addition & 1 deletion Libraries/Components/Switch/SwitchNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,5 +54,5 @@ export const Commands: NativeCommands = codegenNativeCommands<NativeCommands>({

export default (codegenNativeComponent<NativeProps>('Switch', {
paperComponentName: 'RCTSwitch',
excludedPlatform: 'android',
excludedPlatforms: ['android'],
}): ComponentType);
2 changes: 1 addition & 1 deletion Libraries/Utilities/codegenNativeComponent.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type Options = $ReadOnly<{|
interfaceOnly?: boolean,
paperComponentName?: string,
paperComponentNameDeprecated?: string,
excludedPlatform?: 'iOS' | 'android',
excludedPlatforms?: $ReadOnlyArray<'iOS' | 'android'>,
|}>;

export type NativeComponentType<T> = HostComponent<T>;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
import com.facebook.react.uimanager.LayoutShadowNode;

public class DatePickerManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & DatePickerManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public DatePickerManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "date":
mViewManager.setDate(view, value == null ? 0f : ((Double) value).floatValue());
break;
case "initialDate":
mViewManager.setInitialDate(view, value == null ? 0f : ((Double) value).floatValue());
break;
case "locale":
mViewManager.setLocale(view, value == null ? null : (String) value);
break;
case "maximumDate":
mViewManager.setMaximumDate(view, value == null ? 0f : ((Double) value).floatValue());
break;
case "minimumDate":
mViewManager.setMinimumDate(view, value == null ? 0f : ((Double) value).floatValue());
break;
case "minuteInterval":
mViewManager.setMinuteInterval(view, value == null ? 1 : ((Double) value).intValue());
break;
case "mode":
mViewManager.setMode(view, (String) value);
break;
case "timeZoneOffsetInMinutes":
mViewManager.setTimeZoneOffsetInMinutes(view, value == null ? 0f : ((Double) value).floatValue());
break;
default:
super.setProperty(view, propName, value);
}
}

public void receiveCommand(DatePickerManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
switch (commandName) {
case "setNativeDate":
viewManager.setNativeDate(view, (float) args.getDouble(0));
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;

public interface DatePickerManagerInterface<T extends View> {
void setDate(T view, float value);
void setInitialDate(T view, float value);
void setLocale(T view, @Nullable String value);
void setMaximumDate(T view, float value);
void setMinimumDate(T view, float value);
void setMinuteInterval(T view, @Nullable Integer value);
void setMode(T view, @Nullable String value);
void setTimeZoneOffsetInMinutes(T view, float value);
void setNativeDate(T view, float date);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaDelegate.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
import com.facebook.react.uimanager.LayoutShadowNode;

public class PullToRefreshViewManagerDelegate<T extends View, U extends BaseViewManagerInterface<T> & PullToRefreshViewManagerInterface<T>> extends BaseViewManagerDelegate<T, U> {
public PullToRefreshViewManagerDelegate(U viewManager) {
super(viewManager);
}
@Override
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case "tintColor":
mViewManager.setTintColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "titleColor":
mViewManager.setTitleColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "title":
mViewManager.setTitle(view, value == null ? null : (String) value);
break;
case "refreshing":
mViewManager.setRefreshing(view, value == null ? false : (boolean) value);
break;
default:
super.setProperty(view, propName, value);
}
}

public void receiveCommand(PullToRefreshViewManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
switch (commandName) {
case "setNativeRefreshing":
viewManager.setNativeRefreshing(view, args.getBoolean(0));
break;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated by codegen project: GeneratePropsJavaInterface.js
*/

package com.facebook.react.viewmanagers;

import android.view.View;
import androidx.annotation.Nullable;

public interface PullToRefreshViewManagerInterface<T extends View> {
void setTintColor(T view, @Nullable Integer value);
void setTitleColor(T view, @Nullable Integer value);
void setTitle(T view, @Nullable String value);
void setRefreshing(T view, boolean value);
void setNativeRefreshing(T view, boolean refreshing);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
import com.facebook.react.uimanager.LayoutShadowNode;
Expand All @@ -29,25 +31,33 @@ public void setProperty(T view, String propName, @Nullable Object value) {
mViewManager.setValue(view, value == null ? false : (boolean) value);
break;
case "tintColor":
mViewManager.setTintColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setTintColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "onTintColor":
mViewManager.setOnTintColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setOnTintColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "thumbTintColor":
mViewManager.setThumbTintColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setThumbTintColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "thumbColor":
mViewManager.setThumbColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setThumbColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "trackColorForFalse":
mViewManager.setTrackColorForFalse(view, value == null ? null : ((Double) value).intValue());
mViewManager.setTrackColorForFalse(view, ColorPropConverter.getColor(value, view.getContext()));
break;
case "trackColorForTrue":
mViewManager.setTrackColorForTrue(view, value == null ? null : ((Double) value).intValue());
mViewManager.setTrackColorForTrue(view, ColorPropConverter.getColor(value, view.getContext()));
break;
default:
super.setProperty(view, propName, value);
}
}

public void receiveCommand(SwitchManagerInterface<T> viewManager, T view, String commandName, ReadableArray args) {
switch (commandName) {
case "setValue":
viewManager.setValue(view, args.getBoolean(0));
break;
}
}
}
6 changes: 4 additions & 2 deletions packages/react-native-codegen/src/CodegenSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

'use strict';

export type PlatformType = 'iOS' | 'android';

export type CommandsFunctionTypeAnnotation = $ReadOnly<{|
type: 'FunctionTypeAnnotation',
params: $ReadOnlyArray<CommandsFunctionTypeParamAnnotation>,
Expand Down Expand Up @@ -309,8 +311,8 @@ export type OptionsShape = $ReadOnly<{|
// Does not check for new name
paperComponentName?: string,

// Use for components that are not used on one or the other platform.
excludedPlatform?: 'iOS' | 'android',
// Use for components that are not used on other platforms.
excludedPlatforms?: $ReadOnlyArray<PlatformType>,

// Use for components currently being renamed in paper
// Will use new name if it is available and fallback to this name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,10 @@ module.exports = {
return Object.keys(components)
.filter(componentName => {
const component = components[componentName];
return component.excludedPlatform !== 'iOS';
return !(
component.excludedPlatforms &&
component.excludedPlatforms.includes('iOS')
);
})
.map(componentName => {
return [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ module.exports = {
return Object.keys(components)
.filter(componentName => {
const component = components[componentName];
return component.excludedPlatform !== 'iOS';
return !(
component.excludedPlatforms &&
component.excludedPlatforms.includes('iOS')
);
})
.map(componentName => {
const component = components[componentName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,10 @@ module.exports = {
return Object.keys(components)
.filter(componentName => {
const component = components[componentName];
return component.excludedPlatform !== 'iOS';
return !(
component.excludedPlatforms &&
component.excludedPlatforms.includes('iOS')
);
})
.map(componentName => {
const component = components[componentName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ module.exports = {
return Object.keys(components)
.filter(componentName => {
const component = components[componentName];
return component.excludedPlatform !== 'android';
return !(
component.excludedPlatforms &&
component.excludedPlatforms.includes('android')
);
})
.forEach(componentName => {
const component = components[componentName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,10 @@ module.exports = {
return Object.keys(components)
.filter(componentName => {
const component = components[componentName];
return component.excludedPlatform !== 'android';
return !(
component.excludedPlatforms &&
component.excludedPlatforms.includes('android')
);
})
.forEach(componentName => {
const component = components[componentName];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1524,7 +1524,28 @@ const EXCLUDE_ANDROID: SchemaType = {
ExcludedAndroid: {
components: {
ExcludedAndroidComponent: {
excludedPlatform: 'android',
excludedPlatforms: ['android'],
extendsProps: [
{
type: 'ReactNativeBuiltInType',
knownTypeName: 'ReactNativeCoreViewProps',
},
],
events: [],
props: [],
commands: [],
},
},
},
},
};

const EXCLUDE_ANDROID_IOS: SchemaType = {
modules: {
ExcludedAndroidIos: {
components: {
ExcludedAndroidIosComponent: {
excludedPlatforms: ['android', 'iOS'],
extendsProps: [
{
type: 'ReactNativeBuiltInType',
Expand Down Expand Up @@ -1566,4 +1587,5 @@ module.exports = {
COMMANDS,
COMMANDS_AND_PROPS,
EXCLUDE_ANDROID,
EXCLUDE_ANDROID_IOS,
};
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,32 @@ using ExcludedAndroidComponentComponentDescriptor = ConcreteComponentDescriptor<
}
`;

exports[`GenerateComponentDescriptorH can generate fixture EXCLUDE_ANDROID_IOS 1`] = `
Map {
"ComponentDescriptors.h" => "
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#pragma once
#include <react/components/EXCLUDE_ANDROID_IOS/ShadowNodes.h>
#include <react/core/ConcreteComponentDescriptor.h>
namespace facebook {
namespace react {
using ExcludedAndroidIosComponentComponentDescriptor = ConcreteComponentDescriptor<ExcludedAndroidIosComponentShadowNode>;
} // namespace react
} // namespace facebook
",
}
`;

exports[`GenerateComponentDescriptorH can generate fixture FLOAT_PROPS 1`] = `
Map {
"ComponentDescriptors.h" => "
Expand Down
Loading

0 comments on commit 16ea9ba

Please sign in to comment.