@shopify/react-native-skia 1.5.7 → 1.5.9
Sign up to get free protection for your applications and to get access to all the features.
- package/android/CMakeLists.txt +1 -2
- package/android/cpp/jni/JniPlatformContext.cpp +0 -49
- package/android/cpp/jni/include/JniPlatformContext.h +1 -17
- package/android/cpp/jni/include/JniSkiaBaseView.h +0 -2
- package/android/cpp/jni/include/JniSkiaDomView.h +0 -3
- package/android/cpp/jni/include/JniSkiaManager.h +0 -2
- package/android/cpp/jni/include/JniSkiaPictureView.h +0 -3
- package/android/cpp/rnskia-android/MainThreadDispatcher.h +69 -0
- package/android/cpp/rnskia-android/OpenGLContext.h +3 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.cpp +1 -1
- package/android/cpp/rnskia-android/OpenGLWindowContext.h +4 -5
- package/android/cpp/rnskia-android/RNSkAndroidPlatformContext.h +10 -11
- package/android/cpp/rnskia-android/RNSkAndroidView.h +3 -13
- package/android/cpp/rnskia-android/RNSkOpenGLCanvasProvider.cpp +0 -1
- package/android/src/main/java/com/shopify/reactnative/skia/PlatformContext.java +0 -85
- package/android/src/main/java/com/shopify/reactnative/skia/RNSkiaModule.java +1 -21
- package/android/src/main/java/com/shopify/reactnative/skia/SkiaManager.java +0 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerDelegate.java +1 -4
- package/android/src/paper/java/com/facebook/react/viewmanagers/SkiaDomViewManagerInterface.java +0 -1
- package/cpp/api/JsiSkImage.h +20 -4
- package/cpp/rnskia/RNSkManager.cpp +2 -3
- package/cpp/rnskia/RNSkPlatformContext.h +6 -114
- package/cpp/rnskia/RNSkView.h +21 -77
- package/ios/RNSkia-iOS/MetalContext.h +2 -0
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.h +4 -10
- package/ios/RNSkia-iOS/RNSkiOSPlatformContext.mm +6 -16
- package/ios/RNSkia-iOS/SkiaDomView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaDomViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaPictureView.mm +0 -1
- package/ios/RNSkia-iOS/SkiaPictureViewManager.mm +0 -6
- package/ios/RNSkia-iOS/SkiaUIView.h +0 -1
- package/ios/RNSkia-iOS/SkiaUIView.mm +1 -14
- package/lib/commonjs/renderer/Canvas.d.ts +1 -0
- package/lib/commonjs/renderer/Canvas.js +5 -5
- package/lib/commonjs/renderer/Canvas.js.map +1 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/commonjs/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/commonjs/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/commonjs/views/SkiaBaseWebView.js +1 -19
- package/lib/commonjs/views/SkiaBaseWebView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.d.ts +8 -1
- package/lib/commonjs/views/SkiaDomView.js +14 -2
- package/lib/commonjs/views/SkiaDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaDomView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaDomView.web.js.map +1 -1
- package/lib/commonjs/views/SkiaJSDomView.d.ts +12 -6
- package/lib/commonjs/views/SkiaJSDomView.js +12 -3
- package/lib/commonjs/views/SkiaJSDomView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.d.ts +8 -1
- package/lib/commonjs/views/SkiaPictureView.js +14 -1
- package/lib/commonjs/views/SkiaPictureView.js.map +1 -1
- package/lib/commonjs/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/commonjs/views/SkiaPictureView.web.js.map +1 -1
- package/lib/commonjs/views/types.d.ts +2 -12
- package/lib/commonjs/views/types.js.map +1 -1
- package/lib/module/renderer/Canvas.d.ts +1 -0
- package/lib/module/renderer/Canvas.js +5 -5
- package/lib/module/renderer/Canvas.js.map +1 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/module/specs/SkiaPictureViewNativeComponent.js.map +1 -1
- package/lib/module/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/module/views/SkiaBaseWebView.js +1 -19
- package/lib/module/views/SkiaBaseWebView.js.map +1 -1
- package/lib/module/views/SkiaDomView.d.ts +8 -1
- package/lib/module/views/SkiaDomView.js +14 -2
- package/lib/module/views/SkiaDomView.js.map +1 -1
- package/lib/module/views/SkiaDomView.web.d.ts +3 -3
- package/lib/module/views/SkiaDomView.web.js.map +1 -1
- package/lib/module/views/SkiaJSDomView.d.ts +12 -6
- package/lib/module/views/SkiaJSDomView.js +12 -3
- package/lib/module/views/SkiaJSDomView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.d.ts +8 -1
- package/lib/module/views/SkiaPictureView.js +14 -1
- package/lib/module/views/SkiaPictureView.js.map +1 -1
- package/lib/module/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/module/views/SkiaPictureView.web.js.map +1 -1
- package/lib/module/views/types.d.ts +2 -12
- package/lib/module/views/types.js.map +1 -1
- package/lib/typescript/lib/commonjs/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/commonjs/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/commonjs/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/commonjs/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaBaseWebView.d.ts +0 -11
- package/lib/typescript/lib/module/views/SkiaDomView.d.ts +3 -0
- package/lib/typescript/lib/module/views/SkiaJSDomView.d.ts +2 -0
- package/lib/typescript/lib/module/views/SkiaPictureView.d.ts +3 -0
- package/lib/typescript/src/renderer/Canvas.d.ts +1 -0
- package/lib/typescript/src/specs/SkiaPictureViewNativeComponent.d.ts +0 -1
- package/lib/typescript/src/views/SkiaBaseWebView.d.ts +1 -12
- package/lib/typescript/src/views/SkiaDomView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaDomView.web.d.ts +3 -3
- package/lib/typescript/src/views/SkiaJSDomView.d.ts +12 -6
- package/lib/typescript/src/views/SkiaPictureView.d.ts +8 -1
- package/lib/typescript/src/views/SkiaPictureView.web.d.ts +3 -3
- package/lib/typescript/src/views/types.d.ts +2 -12
- package/package.json +1 -1
- package/react-native-skia.podspec +2 -2
- package/src/renderer/Canvas.tsx +4 -3
- package/src/renderer/__tests__/e2e/Image.spec.tsx +2 -64
- package/src/skia/__tests__/assets/oslo-mini.jpg +0 -0
- package/src/specs/SkiaPictureViewNativeComponent.ts +0 -1
- package/src/views/SkiaBaseWebView.tsx +3 -19
- package/src/views/SkiaDomView.tsx +23 -4
- package/src/views/SkiaDomView.web.tsx +3 -3
- package/src/views/SkiaJSDomView.tsx +30 -9
- package/src/views/SkiaPictureView.tsx +22 -2
- package/src/views/SkiaPictureView.web.tsx +3 -3
- package/src/views/types.ts +2 -13
- package/cpp/rnskia/RNSkDispatchQueue.cpp +0 -73
- package/cpp/rnskia/RNSkDispatchQueue.h +0 -49
- package/ios/RNSkia-iOS/DisplayLink.h +0 -17
- package/ios/RNSkia-iOS/DisplayLink.mm +0 -41
@@ -7,19 +7,29 @@ import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeCompon
|
|
7
7
|
import { JsiDrawingContext } from "../dom/types";
|
8
8
|
|
9
9
|
import { SkiaViewApi } from "./api";
|
10
|
-
import type {
|
10
|
+
import type {
|
11
|
+
SkiaPictureViewNativeProps,
|
12
|
+
SkiaDomViewNativeProps,
|
13
|
+
} from "./types";
|
11
14
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
12
15
|
|
13
|
-
const NativeSkiaPictureView: HostComponent<
|
16
|
+
const NativeSkiaPictureView: HostComponent<SkiaPictureViewNativeProps> =
|
14
17
|
Platform.OS !== "web"
|
15
18
|
? SkiaPictureViewNativeComponent
|
16
19
|
: // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
17
20
|
(null as any);
|
18
21
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
22
|
+
interface SkiaDomViewProps extends SkiaDomViewNativeProps {
|
23
|
+
mode?: "default" | "continuous";
|
24
|
+
}
|
25
|
+
|
26
|
+
type SkiaJSDomViewProps = SkiaDomViewProps & {
|
27
|
+
Skia: Skia;
|
28
|
+
mode?: "default" | "continuous";
|
29
|
+
};
|
30
|
+
|
31
|
+
export class SkiaJSDomView extends React.Component<SkiaJSDomViewProps> {
|
32
|
+
constructor(props: SkiaJSDomViewProps) {
|
23
33
|
super(props);
|
24
34
|
this._nativeId = SkiaViewNativeId.current++;
|
25
35
|
const { root, onSize } = props;
|
@@ -31,9 +41,18 @@ export class SkiaJSDomView extends React.Component<
|
|
31
41
|
assertSkiaViewApi();
|
32
42
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
33
43
|
}
|
44
|
+
this.tick();
|
34
45
|
}
|
35
46
|
|
36
47
|
private _nativeId: number;
|
48
|
+
private requestId = 0;
|
49
|
+
|
50
|
+
private tick() {
|
51
|
+
this.redraw();
|
52
|
+
if (this.props.mode === "continuous") {
|
53
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
54
|
+
}
|
55
|
+
}
|
37
56
|
|
38
57
|
public get nativeId() {
|
39
58
|
return this._nativeId;
|
@@ -49,6 +68,7 @@ export class SkiaJSDomView extends React.Component<
|
|
49
68
|
assertSkiaViewApi();
|
50
69
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
51
70
|
}
|
71
|
+
this.tick();
|
52
72
|
}
|
53
73
|
|
54
74
|
/**
|
@@ -67,7 +87,6 @@ export class SkiaJSDomView extends React.Component<
|
|
67
87
|
public redraw() {
|
68
88
|
assertSkiaViewApi();
|
69
89
|
this.draw();
|
70
|
-
//SkiaViewApi.requestRedraw(this._nativeId);
|
71
90
|
}
|
72
91
|
|
73
92
|
private draw() {
|
@@ -89,15 +108,17 @@ export class SkiaJSDomView extends React.Component<
|
|
89
108
|
componentWillUnmount(): void {
|
90
109
|
assertSkiaViewApi();
|
91
110
|
SkiaViewApi.setJsiProperty(this._nativeId, "picture", null);
|
111
|
+
if (this.requestId) {
|
112
|
+
cancelAnimationFrame(this.requestId);
|
113
|
+
}
|
92
114
|
}
|
93
115
|
|
94
116
|
render() {
|
95
|
-
const {
|
117
|
+
const { debug = false, ...viewProps } = this.props;
|
96
118
|
return (
|
97
119
|
<NativeSkiaPictureView
|
98
120
|
collapsable={false}
|
99
121
|
nativeID={`${this._nativeId}`}
|
100
|
-
mode={mode}
|
101
122
|
debug={debug}
|
102
123
|
{...viewProps}
|
103
124
|
/>
|
@@ -4,12 +4,18 @@ import type { SkRect } from "../skia/types";
|
|
4
4
|
import SkiaPictureViewNativeComponent from "../specs/SkiaPictureViewNativeComponent";
|
5
5
|
|
6
6
|
import { SkiaViewApi } from "./api";
|
7
|
-
import type {
|
7
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
8
8
|
import { SkiaViewNativeId } from "./SkiaViewNativeId";
|
9
9
|
|
10
10
|
const NativeSkiaPictureView = SkiaPictureViewNativeComponent;
|
11
11
|
|
12
|
+
interface SkiaPictureViewProps extends SkiaPictureViewNativeProps {
|
13
|
+
mode?: "default" | "continuous";
|
14
|
+
}
|
15
|
+
|
12
16
|
export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
17
|
+
private requestId = 0;
|
18
|
+
|
13
19
|
constructor(props: SkiaPictureViewProps) {
|
14
20
|
super(props);
|
15
21
|
this._nativeId = SkiaViewNativeId.current++;
|
@@ -22,6 +28,7 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
22
28
|
assertSkiaViewApi();
|
23
29
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
24
30
|
}
|
31
|
+
this.tick();
|
25
32
|
}
|
26
33
|
|
27
34
|
private _nativeId: number;
|
@@ -40,6 +47,20 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
40
47
|
assertSkiaViewApi();
|
41
48
|
SkiaViewApi.setJsiProperty(this._nativeId, "onSize", onSize);
|
42
49
|
}
|
50
|
+
this.tick();
|
51
|
+
}
|
52
|
+
|
53
|
+
componentWillUnmount() {
|
54
|
+
if (this.requestId) {
|
55
|
+
cancelAnimationFrame(this.requestId);
|
56
|
+
}
|
57
|
+
}
|
58
|
+
|
59
|
+
private tick() {
|
60
|
+
this.redraw();
|
61
|
+
if (this.props.mode === "continuous") {
|
62
|
+
this.requestId = requestAnimationFrame(this.tick.bind(this));
|
63
|
+
}
|
43
64
|
}
|
44
65
|
|
45
66
|
/**
|
@@ -66,7 +87,6 @@ export class SkiaPictureView extends React.Component<SkiaPictureViewProps> {
|
|
66
87
|
<NativeSkiaPictureView
|
67
88
|
collapsable={false}
|
68
89
|
nativeID={`${this._nativeId}`}
|
69
|
-
mode={mode ?? "default"}
|
70
90
|
debug={debug}
|
71
91
|
{...viewProps}
|
72
92
|
/>
|
@@ -1,10 +1,10 @@
|
|
1
1
|
import type { SkCanvas } from "../skia/types";
|
2
2
|
|
3
|
-
import type {
|
3
|
+
import type { SkiaPictureViewNativeProps } from "./types";
|
4
4
|
import { SkiaBaseWebView } from "./SkiaBaseWebView";
|
5
5
|
|
6
|
-
export class SkiaPictureView extends SkiaBaseWebView<
|
7
|
-
constructor(props:
|
6
|
+
export class SkiaPictureView extends SkiaBaseWebView<SkiaPictureViewNativeProps> {
|
7
|
+
constructor(props: SkiaPictureViewNativeProps) {
|
8
8
|
super(props);
|
9
9
|
}
|
10
10
|
|
package/src/views/types.ts
CHANGED
@@ -4,10 +4,7 @@ import type { GroupProps, RenderNode } from "../dom/types";
|
|
4
4
|
import type { SkImage, SkPicture, SkRect, SkSize } from "../skia/types";
|
5
5
|
import type { SharedValueType } from "../renderer/processors/Animations/Animations";
|
6
6
|
|
7
|
-
export type DrawMode = "continuous" | "default";
|
8
|
-
|
9
7
|
export type NativeSkiaViewProps = ViewProps & {
|
10
|
-
mode?: DrawMode;
|
11
8
|
debug?: boolean;
|
12
9
|
};
|
13
10
|
|
@@ -25,14 +22,6 @@ export interface ISkiaViewApi {
|
|
25
22
|
}
|
26
23
|
|
27
24
|
export interface SkiaBaseViewProps extends ViewProps {
|
28
|
-
/**
|
29
|
-
* Sets the drawing mode for the skia view. There are two drawing
|
30
|
-
* modes, "continuous" and "default", where the continuous mode will
|
31
|
-
* continuously redraw the view, and the default mode will only
|
32
|
-
* redraw when any of the regular react properties are changed like
|
33
|
-
* sizes and margins.
|
34
|
-
*/
|
35
|
-
mode?: DrawMode;
|
36
25
|
/**
|
37
26
|
* When set to true the view will display information about the
|
38
27
|
* average time it takes to render.
|
@@ -45,10 +34,10 @@ export interface SkiaBaseViewProps extends ViewProps {
|
|
45
34
|
onSize?: SharedValueType<SkSize>;
|
46
35
|
}
|
47
36
|
|
48
|
-
export interface
|
37
|
+
export interface SkiaPictureViewNativeProps extends SkiaBaseViewProps {
|
49
38
|
picture?: SkPicture;
|
50
39
|
}
|
51
40
|
|
52
|
-
export interface
|
41
|
+
export interface SkiaDomViewNativeProps extends SkiaBaseViewProps {
|
53
42
|
root?: RenderNode<GroupProps>;
|
54
43
|
}
|
@@ -1,73 +0,0 @@
|
|
1
|
-
#include "RNSkDispatchQueue.h"
|
2
|
-
|
3
|
-
#include <memory>
|
4
|
-
#include <mutex>
|
5
|
-
#include <utility>
|
6
|
-
|
7
|
-
namespace RNSkia {
|
8
|
-
|
9
|
-
RNSkDispatchQueue::~RNSkDispatchQueue() {
|
10
|
-
// Signal to dispatch threads that it's time to wrap up
|
11
|
-
std::unique_lock<std::mutex> lock(lock_);
|
12
|
-
quit_ = true;
|
13
|
-
lock.unlock();
|
14
|
-
cv_.notify_all();
|
15
|
-
|
16
|
-
// Wait for threads to finish before we exit
|
17
|
-
for (size_t i = 0; i < threads_.size(); i++) {
|
18
|
-
if (threads_[i].joinable()) {
|
19
|
-
threads_[i].join();
|
20
|
-
}
|
21
|
-
}
|
22
|
-
}
|
23
|
-
|
24
|
-
RNSkDispatchQueue::RNSkDispatchQueue(std::string name, size_t thread_cnt)
|
25
|
-
: name_{std::move(name)}, threads_(thread_cnt) {
|
26
|
-
for (size_t i = 0; i < threads_.size(); i++) {
|
27
|
-
threads_[i] =
|
28
|
-
std::thread(&RNSkDispatchQueue::dispatch_thread_handler, this);
|
29
|
-
}
|
30
|
-
}
|
31
|
-
|
32
|
-
void RNSkDispatchQueue::dispatch(const fp_t &op) {
|
33
|
-
std::unique_lock<std::mutex> lock(lock_);
|
34
|
-
q_.push(op);
|
35
|
-
|
36
|
-
// Manual unlocking is done before notifying, to avoid waking up
|
37
|
-
// the waiting thread only to block again (see notify_one for details)
|
38
|
-
lock.unlock();
|
39
|
-
cv_.notify_one();
|
40
|
-
}
|
41
|
-
|
42
|
-
void RNSkDispatchQueue::dispatch(fp_t &&op) {
|
43
|
-
std::unique_lock<std::mutex> lock(lock_);
|
44
|
-
q_.push(std::move(op));
|
45
|
-
|
46
|
-
// Manual unlocking is done before notifying, to avoid waking up
|
47
|
-
// the waiting thread only to block again (see notify_one for details)
|
48
|
-
lock.unlock();
|
49
|
-
cv_.notify_one();
|
50
|
-
}
|
51
|
-
|
52
|
-
void RNSkDispatchQueue::dispatch_thread_handler(void) {
|
53
|
-
std::unique_lock<std::mutex> lock(lock_);
|
54
|
-
|
55
|
-
do {
|
56
|
-
// Wait until we have data or a quit signal
|
57
|
-
cv_.wait(lock, [this] { return (q_.size() || quit_); });
|
58
|
-
|
59
|
-
// after wait, we own the lock
|
60
|
-
if (!quit_ && q_.size()) {
|
61
|
-
auto op = std::move(q_.front());
|
62
|
-
q_.pop();
|
63
|
-
|
64
|
-
// unlock now that we're done messing with the queue
|
65
|
-
lock.unlock();
|
66
|
-
|
67
|
-
op();
|
68
|
-
|
69
|
-
lock.lock();
|
70
|
-
}
|
71
|
-
} while (!quit_);
|
72
|
-
}
|
73
|
-
} // namespace RNSkia
|
@@ -1,49 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#include <condition_variable>
|
4
|
-
#include <cstdint>
|
5
|
-
#include <cstdio>
|
6
|
-
#include <functional>
|
7
|
-
#include <mutex>
|
8
|
-
#include <queue>
|
9
|
-
#include <string>
|
10
|
-
#include <thread>
|
11
|
-
#include <vector>
|
12
|
-
|
13
|
-
// https://github.com/embeddedartistry/embedded-resources/blob/master/examples/cpp/dispatch.cpp
|
14
|
-
namespace RNSkia {
|
15
|
-
|
16
|
-
class RNSkDispatchQueue {
|
17
|
-
typedef std::function<void(void)> fp_t;
|
18
|
-
|
19
|
-
public:
|
20
|
-
explicit RNSkDispatchQueue(std::string name, size_t thread_cnt = 1);
|
21
|
-
|
22
|
-
~RNSkDispatchQueue();
|
23
|
-
|
24
|
-
// dispatch and copy
|
25
|
-
void dispatch(const fp_t &op);
|
26
|
-
|
27
|
-
// dispatch and move
|
28
|
-
void dispatch(fp_t &&op);
|
29
|
-
|
30
|
-
// Deleted operations
|
31
|
-
RNSkDispatchQueue(const RNSkDispatchQueue &rhs) = delete;
|
32
|
-
|
33
|
-
RNSkDispatchQueue &operator=(const RNSkDispatchQueue &rhs) = delete;
|
34
|
-
|
35
|
-
RNSkDispatchQueue(RNSkDispatchQueue &&rhs) = delete;
|
36
|
-
|
37
|
-
RNSkDispatchQueue &operator=(RNSkDispatchQueue &&rhs) = delete;
|
38
|
-
|
39
|
-
private:
|
40
|
-
std::string name_;
|
41
|
-
std::mutex lock_;
|
42
|
-
std::vector<std::thread> threads_;
|
43
|
-
std::queue<fp_t> q_;
|
44
|
-
std::condition_variable cv_;
|
45
|
-
bool quit_ = false;
|
46
|
-
|
47
|
-
void dispatch_thread_handler(void);
|
48
|
-
};
|
49
|
-
} // namespace RNSkia
|
@@ -1,17 +0,0 @@
|
|
1
|
-
#pragma once
|
2
|
-
|
3
|
-
#import <CoreFoundation/CoreFoundation.h>
|
4
|
-
#import <UIKit/UIKit.h>
|
5
|
-
|
6
|
-
typedef void (^block_t)(double);
|
7
|
-
@interface DisplayLink : NSObject {
|
8
|
-
CADisplayLink *_displayLink;
|
9
|
-
}
|
10
|
-
|
11
|
-
@property(nonatomic, copy) block_t updateBlock;
|
12
|
-
|
13
|
-
- (void)start:(block_t)block;
|
14
|
-
|
15
|
-
- (void)stop;
|
16
|
-
|
17
|
-
@end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
#import "DisplayLink.h"
|
2
|
-
|
3
|
-
@implementation DisplayLink
|
4
|
-
|
5
|
-
- (void)start:(block_t)block {
|
6
|
-
self.updateBlock = block;
|
7
|
-
// check whether the loop is already running
|
8
|
-
if (_displayLink == nil) {
|
9
|
-
// specify update method
|
10
|
-
_displayLink = [CADisplayLink displayLinkWithTarget:self
|
11
|
-
selector:@selector(update:)];
|
12
|
-
|
13
|
-
if (@available(iOS 15.0, *)) {
|
14
|
-
CAFrameRateRange rate = CAFrameRateRangeMake(60, 120, 120);
|
15
|
-
_displayLink.preferredFrameRateRange = rate;
|
16
|
-
} else {
|
17
|
-
_displayLink.preferredFramesPerSecond = 60;
|
18
|
-
}
|
19
|
-
|
20
|
-
// add the display link to the main run loop
|
21
|
-
[_displayLink addToRunLoop:[NSRunLoop mainRunLoop]
|
22
|
-
forMode:NSRunLoopCommonModes];
|
23
|
-
}
|
24
|
-
}
|
25
|
-
|
26
|
-
- (void)stop {
|
27
|
-
// check whether the loop is already stopped
|
28
|
-
if (_displayLink != nil) {
|
29
|
-
// if the display link is present, it gets invalidated (loop stops)
|
30
|
-
|
31
|
-
[_displayLink invalidate];
|
32
|
-
_displayLink = nil;
|
33
|
-
}
|
34
|
-
}
|
35
|
-
|
36
|
-
- (void)update:(CADisplayLink *)sender {
|
37
|
-
double time = [sender timestamp];
|
38
|
-
_updateBlock(time);
|
39
|
-
}
|
40
|
-
|
41
|
-
@end
|