Fix crash on overlayColor usage (#20929)

Summary:
see snack for demo on the issue: https://snack.expo.io/jyrno42/overlaycolor-issue-snack
Pull Request resolved: https://github.com/facebook/react-native/pull/20929

Differential Revision: D9727250

Pulled By: hramos

fbshipit-source-id: 03c95d4b5a38ae51ecebb8615fda1af9599c0508
This commit is contained in:
Jyrno Ader 2018-09-07 14:12:30 -07:00 committed by Facebook Github Bot
parent fe4f03517c
commit 6bc483c8cc
4 changed files with 61 additions and 1 deletions

View File

@ -0,0 +1,27 @@
/**
* Copyright (c) 2014-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.tests;
import android.view.View;
import com.facebook.react.testing.ReactAppInstrumentationTestCase;
/**
* Simple test case for passing overlayColor prop to the Image component
*/
public class ImageOverlayColorTestCase extends ReactAppInstrumentationTestCase {
@Override
protected String getReactApplicationKeyUnderTest() {
return "ImageOverlayColorTestApp";
}
public void testOverlayColorDoesNotCrash() {
View image = getViewByTestId("image");
assertNotNull(image);
}
}

View File

@ -0,0 +1,29 @@
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
var React = require('React');
var Image = require('Image');
class ImageOverlayColorTestApp extends React.Component {
render() {
const uri =
'data:image/gif;base64,' +
'R0lGODdhMAAwAPAAAAAAAP///ywAAAAAMAAwAAAC8IyPqcvt3wCcDkiLc7C0qwyGHhSWpjQu5yqmCYsapy' +
'uvUUlvONmOZtfzgFzByTB10QgxOR0TqBQejhRNzOfkVJ+5YiUqrXF5Y5lKh/DeuNcP5yLWGsEbtLiOSpa/' +
'TPg7JpJHxyendzWTBfX0cxOnKPjgBzi4diinWGdkF8kjdfnycQZXZeYGejmJlZeGl9i2icVqaNVailT6F5' +
'iJ90m6mvuTS4OK05M0vDk0Q4XUtwvKOzrcd3iq9uisF81M1OIcR7lEewwcLp7tuNNkM3uNna3F2JQFo97V' +
'riy/Xl4/f1cf5VWzXyym7PHhhx4dbgYKAAA7';
return <Image testID="image" source={{uri: uri}} overlayColor="#FF0000" />;
}
}
module.exports = ImageOverlayColorTestApp;

View File

@ -54,6 +54,10 @@ var apps = [
component: () =>
require('ScrollViewTestModule').HorizontalScrollViewTestApp,
},
{
appKey: 'ImageOverlayColorTestApp',
component: () => require('ImageOverlayColorTestApp'),
},
{
appKey: 'InitialPropsTestApp',
component: () => require('InitialPropsTestApp'),

View File

@ -109,7 +109,7 @@ public class ReactImageManager extends SimpleViewManager<ReactImageView> {
}
}
@ReactProp(name = "overlayColor")
@ReactProp(name = "overlayColor", customType = "Color")
public void setOverlayColor(ReactImageView view, @Nullable Integer overlayColor) {
if (overlayColor == null) {
view.setOverlayColor(Color.TRANSPARENT);