-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor to extendable skia views (#899)
- Loading branch information
Showing
60 changed files
with
2,188 additions
and
1,408 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import React from "react"; | ||
import { StyleSheet } from "react-native"; | ||
import { usePicture, Skia, SkiaPictureView } from "@shopify/react-native-skia"; | ||
|
||
export const PictureViewExample = () => { | ||
// Create picture | ||
const picture = usePicture( | ||
{ x: 0, y: 0, width: 100, height: 100 }, | ||
(canvas) => { | ||
const paint = Skia.Paint(); | ||
paint.setColor(Skia.Color("pink")); | ||
canvas.drawRect({ x: 0, y: 0, width: 100, height: 100 }, paint); | ||
|
||
const circlePaint = Skia.Paint(); | ||
circlePaint.setColor(Skia.Color("orange")); | ||
canvas.drawCircle(50, 50, 50, circlePaint); | ||
} | ||
); | ||
|
||
return <SkiaPictureView style={styles.container} picture={picture} debug />; | ||
}; | ||
|
||
const styles = StyleSheet.create({ | ||
container: { | ||
flex: 1, | ||
}, | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,15 @@ | ||
#include "JniPlatformContext.h" | ||
#include "JniSkiaDrawView.h" | ||
#include "JniSkiaPictureView.h" | ||
#include "JniSkiaManager.h" | ||
#include <fbjni/fbjni.h> | ||
#include <jni.h> | ||
|
||
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *) { | ||
return facebook::jni::initialize(vm, [] { | ||
RNSkia::JniSkiaManager::registerNatives(); | ||
RNSkia::JniSkiaDrawView::registerNatives(); | ||
RNSkia::JniPlatformContext::registerNatives(); | ||
}); | ||
return facebook::jni::initialize(vm, [] { | ||
RNSkia::JniSkiaManager::registerNatives(); | ||
RNSkia::JniSkiaDrawView::registerNatives(); | ||
RNSkia::JniSkiaPictureView::registerNatives(); | ||
RNSkia::JniPlatformContext::registerNatives(); | ||
}); | ||
} |
This file was deleted.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
#pragma once | ||
|
||
#include <memory> | ||
|
||
#include <fbjni/fbjni.h> | ||
#include <jni.h> | ||
#include <jsi/jsi.h> | ||
|
||
#include <JniSkiaManager.h> | ||
|
||
namespace RNSkia { | ||
using namespace facebook; | ||
using namespace jni; | ||
|
||
class JniSkiaBaseView { | ||
public: | ||
JniSkiaBaseView(jni::alias_ref<JniSkiaManager::javaobject> skiaManager, | ||
std::shared_ptr<RNSkBaseAndroidView> skiaView) : | ||
_manager(skiaManager->cthis()), | ||
_skiaView(skiaView) {} | ||
|
||
~JniSkiaBaseView() {} | ||
|
||
std::shared_ptr<RNSkManager> getSkiaManager() { return _manager->getSkiaManager(); }; | ||
|
||
protected: | ||
virtual void updateTouchPoints(jni::JArrayDouble touches) { | ||
_skiaView->updateTouchPoints(touches); | ||
} | ||
|
||
virtual void surfaceAvailable(jobject surface, int width, int height) { | ||
_skiaView->surfaceAvailable(surface, width, height); | ||
} | ||
|
||
virtual void surfaceSizeChanged(int width, int height) { | ||
_skiaView->surfaceSizeChanged(width, height); | ||
} | ||
|
||
virtual void surfaceDestroyed() { | ||
_skiaView->surfaceDestroyed(); | ||
} | ||
|
||
virtual void setMode(std::string mode) { | ||
_skiaView->setMode(mode); | ||
} | ||
|
||
virtual void setDebugMode(bool show) { | ||
_skiaView->setShowDebugInfo(show); | ||
} | ||
|
||
virtual void registerView(int nativeId) { | ||
getSkiaManager()->registerSkiaView(nativeId, | ||
_skiaView->getSkiaView()); | ||
} | ||
|
||
virtual void unregisterView() { | ||
getSkiaManager()->setSkiaView(_skiaView->getSkiaView()->getNativeId(), nullptr); | ||
getSkiaManager()->unregisterSkiaView( | ||
_skiaView->getSkiaView()->getNativeId()); | ||
_skiaView->viewDidUnmount(); | ||
} | ||
|
||
private: | ||
JniSkiaManager *_manager; | ||
std::shared_ptr<RNSkBaseAndroidView> _skiaView; | ||
}; | ||
|
||
} // namespace RNSkia |
Oops, something went wrong.