gre / react-native-view-shot

Snapshot a React Native view and save it to an image
https://github.com/gre/react-native-view-shot-example
MIT License
2.64k stars 344 forks source link

Fix: iOS base64 and data-uri formats add unnecessary line breaks to base64 string #501

Closed jkadamczyk closed 4 months ago

jkadamczyk commented 7 months ago

What

After upgrading the React Native version to 0.72 I started to notice problems with displaying base64 view shots in <Image /> components. Turns out it was because there were line breaks in the base64 string produced by the view shot library.

The line breaks were there all the time, but I think they might unnecessary. Android implementation produces base64 string without line breaks.

Changes

I changed the options passed to base64EncodeStringWithOptions call in Objective-C. The options that can be passed are an ObjC option set. The options have values which is value of 1 but bit shifted left by different offsets. The initial value is 1 then 2, 4 etc. These options can be combined using logical OR | but we can also pass none by passing value of 0.

I found some information here https://apple-dev.groups.io/g/cocoa/topic/nsdata_base64encoding_vs/17101984

Let me know what you think of this change. I tested it in my project and it now lives there as a patch-package patch.

jkadamczyk commented 4 months ago

Hey @gre not sure what your process for merging PRs is, but I see you approved, but seems like only you can merge it. If you think it's okay to include it now, I would be more than happy to see it merged.

lmk what you think, have a nice day!

gre commented 4 months ago

Sorry for missing this, i'll release an alpha with this fix so we can use it to test it a bit more.

jkadamczyk commented 4 months ago

Thank you!