-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial implementation of isPointInFill
- Loading branch information
Showing
6 changed files
with
285 additions
and
3 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
android/src/main/java/com/horcrux/svg/RNSVGRenderableManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/* | ||
* Copyright (c) 2015-present, Horcrux. | ||
* All rights reserved. | ||
* | ||
* This source code is licensed under the MIT-style license found in the | ||
* LICENSE file in the root directory of this source tree. | ||
*/ | ||
|
||
|
||
package com.horcrux.svg; | ||
|
||
import com.facebook.react.bridge.Callback; | ||
import com.facebook.react.bridge.ReactApplicationContext; | ||
import com.facebook.react.bridge.ReactContextBaseJavaModule; | ||
import com.facebook.react.bridge.ReactMethod; | ||
import com.facebook.react.bridge.ReadableMap; | ||
import com.facebook.react.bridge.UiThreadUtil; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
class RNSVGRenderableManager extends ReactContextBaseJavaModule { | ||
RNSVGRenderableManager(ReactApplicationContext reactContext) { | ||
super(reactContext); | ||
} | ||
|
||
@Nonnull | ||
@Override | ||
public String getName() { | ||
return "RNSVGRenderableManager"; | ||
} | ||
|
||
private static void isPointInFill(final int tag, final float[] src, final Callback successCallback, final int attempt) { | ||
UiThreadUtil.runOnUiThread( | ||
new Runnable() { | ||
@Override | ||
public void run() { | ||
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); | ||
|
||
if (svg == null) { | ||
if (attempt < 1) { | ||
RenderableViewManager.runWhenViewIsAvailable(tag, new Runnable() { | ||
@Override | ||
public void run() { | ||
RenderableView svg = RenderableViewManager.getRenderableViewByTag(tag); | ||
if (svg == null) { // Should never happen | ||
successCallback.invoke(false); | ||
return; | ||
} | ||
isPointInFill(tag, src, successCallback, attempt + 1); | ||
} | ||
}); | ||
} else { | ||
successCallback.invoke(false); | ||
} | ||
return; | ||
} else { | ||
float scale = svg.mScale; | ||
src[0] *= scale; | ||
src[1] *= scale; | ||
int i = svg.hitTest(src); | ||
successCallback.invoke(i != -1); | ||
} | ||
} | ||
} | ||
); | ||
} | ||
|
||
@SuppressWarnings("unused") | ||
@ReactMethod | ||
public void isPointInFill(int tag, ReadableMap options, Callback successCallback) { | ||
float x = (float)options.getDouble("x"); | ||
float y = (float)options.getDouble("y"); | ||
float[] src = new float[] { x, y }; | ||
isPointInFill(tag, src, successCallback, 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters