Skip to content

Commit

Permalink
feat: support using native methods using promises instead of callbacks
Browse files Browse the repository at this point in the history
  • Loading branch information
msand committed Oct 4, 2019
1 parent 8d1380a commit c28499b
Showing 1 changed file with 48 additions and 18 deletions.
66 changes: 48 additions & 18 deletions src/elements/Shape.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,24 @@ export default class Shape<P> extends Component<P> {
) => {
this.root && this.root.setNativeProps(props);
};
getBBox = (callback: () => void, options?: SVGBoundingBoxOptions) => {
if (!callback) {
return;
}
getBBox = (callback?: () => void, options?: SVGBoundingBoxOptions) => {
const { fill = true, stroke = true, markers = true, clipped = true } =
options || {};
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return new Promise(resolve => {
RNSVGRenderableManager.getBBox(
handle,
{
fill,
stroke,
markers,
clipped,
},
resolve,
);
});
}
RNSVGRenderableManager.getBBox(
handle,
{
Expand All @@ -72,47 +83,66 @@ export default class Shape<P> extends Component<P> {
},
callback,
);
return undefined;
};
getCTM = (callback: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.getCTM(handle, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.getCTM(handle, callback);
return undefined;
};
getScreenCTM = (callback: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.getScreenCTM(handle, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.getScreenCTM(handle, callback);
return undefined;
};
isPointInFill = (options: DOMPointInit, callback: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.isPointInFill(handle, options, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.isPointInFill(handle, options, callback);
return undefined;
};
isPointInStroke = (options: DOMPointInit, callback: () => void) => {
isPointInStroke = (options: DOMPointInit, callback?: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.isPointInStroke(handle, options, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.isPointInStroke(handle, options, callback);
return undefined;
};
getTotalLength = (callback: () => void) => {
getTotalLength = (callback?: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.getTotalLength(handle, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.getTotalLength(handle, callback);
return undefined;
};
getPointAtLength = (length: number, callback: () => void) => {
const handle = findNodeHandle(this.root as Component);
if (!callback) {
return;
return new Promise(resolve => {
RNSVGRenderableManager.getPointAtLength(handle, { length }, resolve);
});
}
const handle = findNodeHandle(this.root as Component);
RNSVGRenderableManager.getPointAtLength(handle, { length }, callback);
return undefined;
};
}

0 comments on commit c28499b

Please sign in to comment.