Simplify Svg element render method and pickNotNil

This commit is contained in:
Mikael Sand
2019-01-25 16:14:27 +02:00
parent 73e85b69eb
commit f5cdc31934
2 changed files with 12 additions and 11 deletions
+6 -3
View File
@@ -97,6 +97,11 @@ export default class Svg extends Shape {
flex: 0,
} : null;
const o = +opacity;
const opacityStyle = !isNaN(o) ? {
opacity: o,
} : null;
return (
<NativeSvgView
{...props}
@@ -108,9 +113,7 @@ export default class Svg extends Shape {
style={[
styles.svg,
style,
!isNaN(+opacity) && {
opacity: +opacity,
},
opacityStyle,
dimensions,
]}
{...extractResponder(props, this)}
+6 -8
View File
@@ -1,13 +1,11 @@
export function pickNotNil(object) {
const result = {};
const keys = Object.keys(object);
const l = keys.length;
for (let i = 0; i < l; i++) {
const key = keys[i];
const value = object[key];
// eslint-disable-next-line eqeqeq
if (value != null) {
result[key] = value;
for (const key in object) {
if (object.hasOwnProperty(key)) {
const value = object[key];
if (value !== undefined && value !== null) {
result[key] = value;
}
}
}
return result;