Invoke toDataURL on Android in a more proper way

This commit is contained in:
Horcrux
2017-01-22 18:27:35 +08:00
parent 8cd78e830e
commit 3765e52c67
6 changed files with 48 additions and 75 deletions
+3 -23
View File
@@ -8,12 +8,10 @@ import {
StyleSheet,
UIManager,
findNodeHandle,
NativeModules,
Platform
NativeModules
} from 'react-native';
import extractViewBox from '../lib/extract/extractViewBox';
import {ViewBoxAttributes} from '../lib/attributes';
import _ from 'lodash';
const RNSVGSvgViewManager = NativeModules.RNSVGSvgViewManager;
@@ -64,24 +62,8 @@ class Svg extends Component{
this.root.setNativeProps(...args);
};
toDataURL = Platform.OS === 'ios' ? (callback = _.noop) => {
RNSVGSvgViewManager.toDataURL(findNodeHandle(this.root), callback);
} : (callback = _.noop) => {
let node = findNodeHandle(this.root);
this.onDataURLCallbacks.push(callback);
UIManager.dispatchViewManagerCommand(
node,
UIManager.RNSVGSvgView.Commands.toDataURL,
null
);
};
_onDataURL = (e) => {
while (this.onDataURLCallbacks.length) {
let callback = this.onDataURLCallbacks.shift();
callback(e.nativeEvent.base64);
}
toDataURL = (callback: Function) => {
callback && RNSVGSvgViewManager.toDataURL(findNodeHandle(this.root), callback);
};
render() {
@@ -108,7 +90,6 @@ class Svg extends Component{
},
dimensions
]}
onDataURL={this._onDataURL}
/>;
}
}
@@ -119,5 +100,4 @@ const NativeSvgView = requireNativeComponent('RNSVGSvgView', null, {
}
});
export default Svg;