Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions TestsExample/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import Test2071 from './src/Test2071';
import Test2089 from './src/Test2089';
import Test2196 from './src/Test2196';
import Test2266 from './src/Test2266';
import Test1986 from './src/Test1986';

export default function App() {
return <ColorTest />;
Expand Down
29 changes: 29 additions & 0 deletions TestsExample/src/Test1986.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, {useRef, useState} from 'react';
import {Button, Image, View} from 'react-native';
import {Circle, Svg} from 'react-native-svg';

export default () => {
const ref = useRef<Svg>(null);
const [s, setS] = useState('');
return (
<View style={{flex: 1, paddingTop: 100}}>
<Button
onPress={() => {
ref.current?.toDataURL(source => {
setS(source);
console.log(source);
});
}}
title="log data url"
/>
<Image
width={400}
height={300}
source={{uri: `data:image/png;base64,${s}`}}
/>
<Svg width={400} height={300} ref={ref}>
<Circle cx={200} cy={150} r={100} fill="red" />
</Svg>
</View>
);
};
4 changes: 2 additions & 2 deletions android/src/main/java/com/horcrux/svg/SvgView.java
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ String toDataURL() {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
bitmap.recycle();
byte[] bitmapBytes = stream.toByteArray();
return Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
return Base64.encodeToString(bitmapBytes, Base64.NO_WRAP);
}

String toDataURL(int width, int height) {
Expand All @@ -353,7 +353,7 @@ String toDataURL(int width, int height) {
bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
bitmap.recycle();
byte[] bitmapBytes = stream.toByteArray();
return Base64.encodeToString(bitmapBytes, Base64.DEFAULT);
return Base64.encodeToString(bitmapBytes, Base64.NO_WRAP);
}

void enableTouchEvents() {
Expand Down
4 changes: 2 additions & 2 deletions apple/Elements/RNSVGSvgView.mm
Original file line number Diff line number Diff line change
Expand Up @@ -344,10 +344,10 @@ - (NSString *)getDataURLWithBounds:(CGRect)bounds
#endif
#if !TARGET_OS_OSX // [macOS]
NSData *imageData = UIImagePNGRepresentation(image);
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
#else // [macOS
NSData *imageData = UIImagePNGRepresentation(UIGraphicsGetImageFromCurrentImageContext());
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64Encoding64CharacterLineLength];
NSString *base64 = [imageData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed];
UIGraphicsEndImageContext();
#endif // macOS]
return base64;
Expand Down