Skip to content

Support passing imageStyle when rendering internally ImageBackground #3131

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 16, 2024

Conversation

ethanshar
Copy link
Collaborator

@ethanshar ethanshar commented Jun 10, 2024

Description

Pass imageStyle to Image component when internally it renders ImageBackground (whenever we render children inside the Image)
This fix some issues where image styling is not being passed to the Image that rendered by ImageBackground component

See reference in React Native docs

Changelog

Fix nesting image style props in Image component with children (overlay, content)..

Additional info

ticket 4290

Copy link
Contributor

@adids1221 adids1221 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a small comment

@@ -183,6 +185,13 @@ class Image extends PureComponent<Props, State> {
return this.getVerifiedSource(source);
}

getImageStyle = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should wrap this with useMemo, also this.shouldUseImageBackground() should be memoized since we are using it's value more than once and store it's value into variable.
WDYT ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WDYM?
First of all, notice this is a class component, we can't use useMemo here.
Also there's no point in memoizing, notice I return this return borderRadius ? [{borderRadius}, imageStyle] : imageStyle; so if a borderRadius was passed the style will be dynamic anyway and if it wasn't passed, I am just passing the imageStyle prop that the user has passed.

as for this.shouldUseImageBackground() we don't store its value anywhere.. it's just a util method. where do we store its value in a variable?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had some mistake here my bad.
About the getImageStyle you are right since the return statement will return imageStyle.

@adids1221 adids1221 assigned ethanshar and unassigned adids1221 Jun 13, 2024
@ethanshar ethanshar requested a review from adids1221 June 14, 2024 04:47
@ethanshar ethanshar assigned adids1221 and unassigned ethanshar Jun 16, 2024
@adids1221 adids1221 merged commit daac57c into master Jun 16, 2024
1 check passed
@adids1221 adids1221 deleted the fix/image_background_image_style branch June 16, 2024 08:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants