Skip to content
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

Custom style doesn't apply to ImageComponent #31

Open
rajtejani opened this issue Apr 11, 2021 · 2 comments
Open

Custom style doesn't apply to ImageComponent #31

rajtejani opened this issue Apr 11, 2021 · 2 comments

Comments

@rajtejani
Copy link

useEffect(() => {
        setImage(
            <ImageComponent
                {...props}
                style={[props.style, {
                    width: scalableWidth,
                    height: scalableHeight
                }]}
            />
        );
    }, [scalableHeight, scalableWidth]);


should be refactored to

useEffect(() => {
    const {style, ...restProps} = props;
    setImage(
        <ImageComponent
             {...restProps}
              style={[style, {
                width: scalableWidth,
                height: scalableHeight
            }]}
        />
    );
}, [scalableHeight, scalableWidth]);
@AlkanV
Copy link

AlkanV commented Jul 14, 2021

any update on this? i need to apply customStyles to image component like borderRadius.

@rajtejani
Copy link
Author

@AlkanV You can use this solution which I used in my project.

run
npm install patch-package

Open /node_modules/react-native-scalable-image/index.js

Replace code at Line 41 with below one

useEffect(() => {
    const {style, ...restProps} = props;
    setImage(
        <ImageComponent
             {...restProps}
              style={[style, {
                width: scalableWidth,
                height: scalableHeight
            }]}
        />
    );
}, [scalableHeight, scalableWidth]);

Now run this on your terminal/cmd/powershell
npx patch-package react-native-scalable-image

after that, you will see a patches foldee is created. Add files inside this folder to git.

Then Open package.json and add this postscript inside the script section.

"postinstall": "patch-package",

This is a permanent fix. You will not need to do these changes again whenever you add or remove any dependency.

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

No branches or pull requests

2 participants