-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
toDataURL only works the second time it is executed in old Arch #2233
Comments
Thank you for the issue and the fix. Works well for me 🙏 |
No problem! Im glad it helps 😊 |
Hello @imanderson, Here is my example:
|
@bohdanprog just to be sure: are you using the old arch in your example? |
@buschco Yes, I check the old and new Arch Android and ios platforms. |
@bohdanprog the problem only occurs, if you want to create the data url from a button press like so: import * as React from 'react';
import {Button, SafeAreaView, View} from 'react-native';
import Svg, {Path} from 'react-native-svg';
const SvgLogoWelcome = props => {
const ref = React.useRef();
return (
<View>
<Button
onPress={() => {
ref.current?.toDataURL(base64Image => {
console.log(base64Image, 'data');
});
}}
title="log"
/>
<Svg
ref={ref}
xmlns="http://www.w3.org/2000/svg"
viewBox="0 0 24 24"
fill="black"
{...props}>
<Path d="M12 2c5.514 0 10 4.486 10 10s-4.486 10-10 10S2 17.514 2 12 6.486 2 12 2zm0-2C5.373 0 0 5.373 0 12s5.373 12 12 12 12-5.373 12-12S18.627 0 12 0zm5.507 13.941c-1.512 1.195-3.174 1.931-5.506 1.931-2.334 0-3.996-.736-5.508-1.931L6 14.434C7.127 16.154 9.2 18 12.001 18c2.8 0 4.872-1.846 5.999-3.566l-.493-.493zM8.5 8a1.5 1.5 0 100 3 1.5 1.5 0 000-3zm7 0a1.5 1.5 0 100 3 1.5 1.5 0 000-3z" />
</Svg>
</View>
);
};
function App() {
return (
<SafeAreaView>
<SvgLogoWelcome />
</SafeAreaView>
);
} |
@buschco, thanks for example. I'm going to check that and let you know ;) |
@buschco, here is an example, you can test it. Let me know if it doesn't work because for me everything worked well. |
@bohdanprog To better demonstrate the issue, I added a diff --git a/App.js b/App.js
index ab8d424..4adfc19 100644
--- a/App.js
+++ b/App.js
@@ -8,6 +8,7 @@ const SvgLogoWelcome = (props) => {
<View>
<Button
onPress={() => {
+ console.log("hi");
ref.current?.toDataURL((base64Image) => {
console.log(base64Image, "data", Platform.OS);
}); Screen.Recording.2024-08-09.at.09.24.48.mov |
My bad, you're right, sorry, I thought I misclicked on that button that's why I clicked twice. |
) # Summary Closes #2233 in iOS and old Arch, a callback on `toDataURL` method will only be called the second time of asking. Based on that [PR](#2234) format `RNSVGSvgViewModule` file. ## Test Plan We can easily test that fix by running the `Test2233`, we have an example of the problem. ### What are the steps to reproduce (after prerequisites)? ## Compatibility | OS | Implemented | | ------- | :---------: | | iOS | ✅ |
Hello,
in iOS and old Arch, I found that the callback on toDataURL method will only be called the second time of asking. This is due to when the queue from UIManager in iOS is flushed. See facebook/react-native#1365
I traced the problem to the iOS implementation and will do a PR with my fix.
Environment info
React native info output:
Library version: 14.1.0
Steps To Reproduce
Simply run the Examples App in this repo with
react-native 0.73.4
and go to "Tap the shapes to render the Image below based on the base64-data of the Svg". If you click once, nothing happens, but if you click a second time, the image is rendered.The text was updated successfully, but these errors were encountered: