Skip to content

Commit

Permalink
Update GeneratePropsJavaDelegate to handle PlatformColor
Browse files Browse the repository at this point in the history
Summary:
$title

Changelog:
[Internal]

(Note: this ignores all push blocking failures!)

Reviewed By: rickhanlonii

Differential Revision: D20175915

fbshipit-source-id: 96d75e8cc098ea6ce78288f40191f7bae24d5aa5
  • Loading branch information
elicwhite authored and facebook-github-bot committed Mar 2, 2020
1 parent f4de458 commit 03ac8e8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ function getJavaValueForProp(
case 'NativePrimitiveTypeAnnotation':
switch (typeAnnotation.name) {
case 'ColorPrimitive':
return 'value == null ? null : ((Double) value).intValue()';
return 'ColorPropConverter.getColor(value, view.getContext())';
case 'ImageSourcePrimitive':
return '(ReadableMap) value';
case 'PointPrimitive':
Expand Down Expand Up @@ -230,7 +230,7 @@ function getClassExtendString(component): string {
}

function getDelegateImports(component) {
const imports = getImports(component);
const imports = getImports(component, 'delegate');
// The delegate needs ReadableArray for commands always.
// The interface doesn't always need it
if (component.commands.length > 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@ module.exports = {
const className = getInterfaceJavaClassName(componentName);
const fileName = `${className}.java`;

const imports = getImports(component);
const imports = getImports(component, 'interface');
const propsString = generatePropsString(component, imports);
const commandsString = generateCommandsString(
component,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ function toSafeJavaString(
return parts.map(upperCaseFirst).join('');
}

function getImports(component: ComponentShape): Set<string> {
function getImports(
component: ComponentShape,
type: 'interface' | 'delegate',
): Set<string> {
const imports: Set<string> = new Set();

component.extendsProps.forEach(extendProps => {
Expand All @@ -60,6 +63,9 @@ function getImports(component: ComponentShape): Set<string> {
function addImportsForNativeName(name) {
switch (name) {
case 'ColorPrimitive':
if (type === 'delegate') {
imports.add('import com.facebook.react.bridge.ColorPropConverter;');
}
return;
case 'ImageSourcePrimitive':
imports.add('import com.facebook.react.bridge.ReadableMap;');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ package com.facebook.react.viewmanagers;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
import com.facebook.react.uimanager.LayoutShadowNode;
Expand All @@ -173,7 +174,7 @@ public class ColorPropNativeComponentManagerDelegate<T extends View, U extends B
public void setProperty(T view, String propName, @Nullable Object value) {
switch (propName) {
case \\"tintColor\\":
mViewManager.setTintColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setTintColor(view, ColorPropConverter.getColor(value, view.getContext()));
break;
default:
super.setProperty(view, propName, value);
Expand Down Expand Up @@ -704,6 +705,7 @@ package com.facebook.react.viewmanagers;
import android.view.View;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ColorPropConverter;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.uimanager.BaseViewManagerDelegate;
import com.facebook.react.uimanager.BaseViewManagerInterface;
Expand All @@ -720,10 +722,10 @@ public class ImageColorPropNativeComponentManagerDelegate<T extends View, U exte
mViewManager.setThumbImage(view, (ReadableMap) value);
break;
case \\"color\\":
mViewManager.setColor(view, value == null ? null : ((Double) value).intValue());
mViewManager.setColor(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 \\"point\\":
mViewManager.setPoint(view, (ReadableMap) value);
Expand Down

0 comments on commit 03ac8e8

Please sign in to comment.