Skip to content

Commit

Permalink
Img style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
sheppard committed Aug 23, 2023
1 parent 69c05a7 commit 7d69e39
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
19 changes: 12 additions & 7 deletions packages/material-native/src/components/Img.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,16 @@ export default function Img({ src, onPress, onClick, style, ...props }) {

let resizeMode;
if (
style &&
typeof style.maxHeight === "number" &&
typeof style.maxWidth === "string"
typeof style.maxWidth === "string" &&
style.maxWidth.endsWith("vw")
) {
resizeMode = "contain";
const ratio = source ? source.width / source.height : 1,
const ratio =
source && source.width && source.height
? source.width / source.height
: 1,
maxWidth =
(+style.maxWidth.replace(/vw/g, "") / 100) *
Dimensions.get("window").width;
Expand All @@ -35,6 +40,7 @@ export default function Img({ src, onPress, onClick, style, ...props }) {
width: Math.min(ratio * style.maxHeight, maxWidth),
};
} else if (
style &&
typeof style.maxHeight === "string" &&
typeof style.maxWidth === "string"
) {
Expand All @@ -49,12 +55,11 @@ export default function Img({ src, onPress, onClick, style, ...props }) {
}

const hasSize =
(source && source.width && source.height) ||
(source && (source === src || (source.width && source.height))) ||
props.width ||
props.height ||
style.width ||
style.height;

(style && style.width) ||
(style && style.height);
if (src && !hasSize) {
return null;
} else if (onPress || onClick) {
Expand Down Expand Up @@ -88,7 +93,7 @@ export default function Img({ src, onPress, onClick, style, ...props }) {
}

Img.propTypes = {
src: PropTypes.string,
src: PropTypes.oneOfType(PropTypes.string, PropTypes.number),
width: PropTypes.number,
height: PropTypes.number,
onPress: PropTypes.func,
Expand Down
2 changes: 1 addition & 1 deletion packages/react/src/components/PropertyTable.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ const Value = ({ values, field }) => {

const isInteractive = (values, field) => {
const result = Value({ values, field });
if (typeof result !== "string") {
if (result && typeof result !== "string") {
return true;
} else {
return false;
Expand Down

0 comments on commit 7d69e39

Please sign in to comment.