diff --git a/CanvasNative.podspec b/CanvasNative.podspec index b588bdbff..789dd941e 100644 --- a/CanvasNative.podspec +++ b/CanvasNative.podspec @@ -13,7 +13,7 @@ Pod::Spec.new do |s| s.author = { "Osei Fortune" => "fortune.osei@yahoo.com" } - s.platform = :ios, "13.0" + s.platforms = { :ios => "13.0", :visionos => "1.0" } s.source = { :git => "https://github.com/nativescript/canvas.git", :tag => "#{s.version}" } diff --git a/Cargo.toml b/Cargo.toml index 6da78366a..75d995aa7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -74,7 +74,7 @@ canvas-webgl = { path = "./crates/canvas-webgl" } canvas-svg = { path = "./crates/canvas-svg" } gl-bindings = { path = "./crates/gl-bindings" } canvas-c = { path = "./crates/canvas-c" } -skia-safe = { version = "0.97.0", features = ["textlayout"] } +skia-safe = { git = "https://github.com/triniwiz/rust-skia", rev = "d4c4011", features = ["textlayout"] } itertools = "0.14.0" ustr = "1.1.0" wgpu-core = { git = "https://github.com/triniwiz/wgpu", rev = "7e0f39f", features = ["wgsl"] } diff --git a/Makefile b/Makefile index 9b2914eba..bb0e49d30 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,5 @@ ARCHS_IOS = x86_64-apple-ios aarch64-apple-ios aarch64-apple-ios-sim +ARCHS_VISIONOS = aarch64-apple-visionos aarch64-apple-visionos-sim ARCHS_ANDROID = i686-linux-android x86_64-linux-android aarch64-linux-android armv7-linux-androideabi XCFRAMEWORK = CanvasNative.xcframework @@ -8,17 +9,22 @@ all: GENERATE_HEADERS ios android ios: $(XCFRAMEWORK) +visionos: $(ARCHS_VISIONOS) + android: GENERATE_ANDROID ios-svg: GENERATE_IOS_SVG +visionos-svg: GENERATE_VISIONOS_SVG + +svg: GENERATE_IOS_SVG GENERATE_VISIONOS_SVG + android-svg: GENERATE_ANDROID_SVG .PHONY: GENERATE_HEADERS GENERATE_HEADERS: ./tools/scripts/build-headers.sh -# --- iOS builds --- .PHONY: $(ARCHS_IOS) $(ARCHS_IOS): %: RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \ @@ -27,7 +33,12 @@ $(ARCHS_IOS): %: $(XCFRAMEWORK): $(ARCHS_IOS) -# --- Android builds --- +.PHONY: $(ARCHS_VISIONOS) +$(ARCHS_VISIONOS): %: + RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \ + cargo +nightly build -Z build-std='std,panic_abort' \ + --target $@ --release -p canvas-ios + .PHONY: $(ARCHS_ANDROID) $(ARCHS_ANDROID): %: ./tools/scripts/build-android.sh $@ @@ -35,7 +46,6 @@ $(ARCHS_ANDROID): %: .PHONY: GENERATE_ANDROID GENERATE_ANDROID: $(ARCHS_ANDROID) -# --- iOS SVG builds --- .PHONY: $(addsuffix _svg,$(ARCHS_IOS)) $(addsuffix _svg,$(ARCHS_IOS)): %_svg: RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \ @@ -45,7 +55,17 @@ $(addsuffix _svg,$(ARCHS_IOS)): %_svg: .PHONY: GENERATE_IOS_SVG GENERATE_IOS_SVG: $(addsuffix _svg,$(ARCHS_IOS)) -# --- Android SVG builds --- +.PHONY: $(addsuffix _svg,$(ARCHS_VISIONOS)) +$(addsuffix _svg,$(ARCHS_VISIONOS)): %_svg: + RUSTFLAGS="-Zlocation-detail=none -Zunstable-options -Cpanic=immediate-abort" \ + cargo +nightly build -Z build-std='std,panic_abort' \ + --target $* --release -p canvas-svg-ios + +.PHONY: GENERATE_VISIONOS_SVG +GENERATE_VISIONOS_SVG: $(addsuffix _svg,$(ARCHS_VISIONOS)) + +.PHONY: ios-svg visionos-svg svg + .PHONY: $(addsuffix _svg,$(ARCHS_ANDROID)) $(addsuffix _svg,$(ARCHS_ANDROID)): %_svg: ./tools/scripts/build-svg-android.sh $* svg @@ -53,7 +73,6 @@ $(addsuffix _svg,$(ARCHS_ANDROID)): %_svg: .PHONY: GENERATE_ANDROID_SVG GENERATE_ANDROID_SVG: $(addsuffix _svg,$(ARCHS_ANDROID)) -# --- Debug targets --- .PHONY: ios_debug ios_debug: $(addsuffix _debug,$(ARCHS_IOS)) @@ -64,11 +83,17 @@ android_debug: $(addsuffix _debug,$(ARCHS_ANDROID)) $(addsuffix _debug,$(ARCHS_IOS)): %_debug: cargo +nightly build --target $* -p canvas-ios +.PHONY: visionos_debug +visionos_debug: $(addsuffix _debug,$(ARCHS_VISIONOS)) + +.PHONY: $(addsuffix _debug,$(ARCHS_VISIONOS)) +$(addsuffix _debug,$(ARCHS_VISIONOS)): %_debug: + cargo +nightly build -Z build-std='std,panic_abort' --target $* -p canvas-ios + .PHONY: $(addsuffix _debug,$(ARCHS_ANDROID)) $(addsuffix _debug,$(ARCHS_ANDROID)): %_debug: ./tools/scripts/build-android.sh $* debug -# --- Clean --- .PHONY: clean clean: rm -rf target \ No newline at end of file diff --git a/NativeScript.podspec b/NativeScript.podspec new file mode 100644 index 000000000..decac067b --- /dev/null +++ b/NativeScript.podspec @@ -0,0 +1,21 @@ +Pod::Spec.new do |s| + s.name = "NativeScript" + s.version = '1.0.0' + s.summary = "V8 + NativeScript runtime headers for canvas and audio-context" + s.license = "MIT" + + s.authors = "Osei Fortune" + s.homepage = "https://github.com/NativeScript/canvas" + s.platforms = { :ios => "12.0", :visionos => "1.0" } + + # Both canvas and audio-context can depend on this pod from the same repo: + # pod 'NativeScript', :git => 'https://github.com/NativeScript/canvas.git', :tag => 'v1.0.0' + s.source = { :git => "https://github.com/NativeScript/canvas.git", :tag => "v#{s.version}" } + s.cocoapods_version = ">= 1.10.1" + + # Headers-only — the NativeScript.xcframework binary is provided by the + # NativeScript runtime at app build time, not by this pod. + s.source_files = "nativescript-v8/Headers/**/*.h" + s.header_mappings_dir = "nativescript-v8/Headers" + s.xcconfig = { 'HEADER_SEARCH_PATHS' => '$(inherited) "${PODS_ROOT}/Headers/Public/NativeScript"' } +end diff --git a/Package.swift b/Package.swift index f7505cfa3..0c3c3c13f 100644 --- a/Package.swift +++ b/Package.swift @@ -1,28 +1,18 @@ -// swift-tools-version:5.3 -// The swift-tools-version declares the minimum version of Swift required to build this package. - +// swift-tools-version:5.9 import PackageDescription let package = Package( name: "CanvasNative", + platforms: [.iOS(.v12), .visionOS(.v1)], products: [ - // Products define the executables and libraries a package produces, and make them visible to other packages. - .library( - name: "CanvasNative", - targets: ["CanvasNative"]), - ], - dependencies: [ - // Dependencies declare other packages that this package depends on. - // .package(url: /* package url */, from: "1.0.0"), + .library(name: "NativeScriptV8", targets: ["NativeScriptV8"]), ], targets: [ - // Targets are the basic building blocks of a package. A target can define a module or a test suite. - // Targets can depend on other targets in this package, and on products in packages this package depends on. .target( - name: "CanvasNative", - dependencies: []), - .testTarget( - name: "CanvasNativeTests", - dependencies: ["CanvasNative"]), + name: "NativeScriptV8", + path: "nativescript-v8", + sources: ["Sources"], + publicHeadersPath: "Headers" + ), ] ) diff --git a/apps/demo/nativescript.config.ts b/apps/demo/nativescript.config.ts index e5605d2c0..0ab9f64e1 100644 --- a/apps/demo/nativescript.config.ts +++ b/apps/demo/nativescript.config.ts @@ -10,9 +10,16 @@ export default { }, appPath: 'src', ios: { - discardUncaughtJsExceptions: false + discardUncaughtJsExceptions: false, + SPMPackages: [ + { + name: 'CanvasNative', + libs: ['NativeScriptV8'], + path: '../../nativescript-v8', + }, + ], }, cli: { - packageManager: 'npm' - } + packageManager: 'npm', + }, } as NativeScriptConfig; diff --git a/apps/demo/package.json b/apps/demo/package.json index 7e2b1bad2..495ded45b 100644 --- a/apps/demo/package.json +++ b/apps/demo/package.json @@ -14,7 +14,7 @@ "@nativescript/canvas-polyfill": "file:../../packages/canvas-polyfill", "@nativescript/canvas-svg": "file:../../packages/canvas-svg", "@nativescript/canvas-three": "file:../../packages/canvas-three", - "@nativescript/core": "file:../../node_modules/@nativescript/core", + "@nativescript/core": "9.0.20", "@pixi-essentials/svg": "file:../../node_modules/@pixi-essentials/svg", "babylonjs": "file:../../node_modules/babylonjs", "babylonjs-materials": "file:../../node_modules/babylonjs-materials", @@ -35,6 +35,6 @@ "@nativescript/android": "~8.9.0", "@nativescript/devtools": "~0.0.1", "@nativescript/ios": "~8.9.0", - "@nativescript/visionos": "~8.9.0" + "@nativescript/visionos": "~9.0.1" } } diff --git a/apps/demo/src/app-root.xml b/apps/demo/src/app-root.xml index bd68181ca..c1b8fca2c 100644 --- a/apps/demo/src/app-root.xml +++ b/apps/demo/src/app-root.xml @@ -2,3 +2,6 @@ + + \ No newline at end of file diff --git a/apps/demo/src/app.ts b/apps/demo/src/app.ts index 198d3c03b..d269b46d7 100644 --- a/apps/demo/src/app.ts +++ b/apps/demo/src/app.ts @@ -9,6 +9,31 @@ import { Canvas } from '@nativescript/canvas'; // const canvas = new Canvas(); // } +const font = new FontFace('Serifa-Bold', 'url(~/fonts/Serifa-Bold.otf)', { + weight: 'bold', +}); + +document.fonts.add(font); + +document.fonts.addEventListener('loading', (event) => { + console.log('loading'); +}); +document.fonts.addEventListener('loadingerror', (event) => { + console.log('loadingerror'); +}); +document.fonts.addEventListener('loadingdone', (event) => { + console.log('loadingdone', event.fontfaces); +}); + +document.fonts + .load('12px Serifa-Bold') + .then((fonts) => { + console.log(document.fonts.check('12px Serifa-Bold')); + }) + .catch(() => { + console.log('error'); + }); + /* @@ -153,7 +178,7 @@ Application.on('launch', (args) => { //require('@nativescript/canvas-polyfill'); if (__ANDROID__) { jp.wasabeef.takt.Takt.stock(Utils.android.getApplicationContext()).seat(jp.wasabeef.takt.Seat.TOP_CENTER).color(-65536); - } else { + } else if (__IOS__) { monitor = GDPerformanceMonitor.new(); monitor.startMonitoringWithConfiguration((label) => { label.backgroundColor = UIColor.blackColor; diff --git a/apps/demo/src/fonts/Serifa-Bold.otf b/apps/demo/src/fonts/Serifa-Bold.otf new file mode 100644 index 000000000..a4e76ce9b Binary files /dev/null and b/apps/demo/src/fonts/Serifa-Bold.otf differ diff --git a/apps/demo/src/plugin-demos/audio-context.ts b/apps/demo/src/plugin-demos/audio-context.ts index f7c03bab0..77d2df340 100644 --- a/apps/demo/src/plugin-demos/audio-context.ts +++ b/apps/demo/src/plugin-demos/audio-context.ts @@ -16,7 +16,7 @@ export function canvasReady(args: EventData) { export function playSample(args: EventData) { const page = (args.object).page as Page; const ctx = page.bindingContext as any; - const testPath = __IOS__ ? '~/assets/file-assets/audio/sine441stereo.mp3' : '~/assets/file-assets/audio/gs-16b-1c-44100hz.wav'; + const testPath = __APPLE__ ? '~/assets/file-assets/audio/sine441stereo.mp3' : '~/assets/file-assets/audio/gs-16b-1c-44100hz.wav'; const resolvedPath = testPath.startsWith('~/') ? testPath.replace('~/', knownFolders.currentApp().path + '/') : testPath; if (ctx && ctx.playUrl) { const p = ctx.playUrl(resolvedPath); diff --git a/apps/demo/src/plugin-demos/canvas-three.ts b/apps/demo/src/plugin-demos/canvas-three.ts index 0188d6a87..5fec5a183 100644 --- a/apps/demo/src/plugin-demos/canvas-three.ts +++ b/apps/demo/src/plugin-demos/canvas-three.ts @@ -8,7 +8,7 @@ export function navigatingTo(args: EventData) { } export function pageLoaded(args) { - if (__IOS__) { + if (__APPLE__) { if (parseFloat(Device.osVersion) >= 26.0) { args.object.viewController.navigationController.interactiveContentPopGestureRecognizer.enabled = false; } diff --git a/apps/demo/src/plugin-demos/canvas.ts b/apps/demo/src/plugin-demos/canvas.ts index 475b91a51..ea3c18ae0 100644 --- a/apps/demo/src/plugin-demos/canvas.ts +++ b/apps/demo/src/plugin-demos/canvas.ts @@ -9,7 +9,7 @@ export function navigatingTo(args: EventData) { } export function pageLoaded(args) { - if (__IOS__) { + if (__APPLE__) { if (parseFloat(Device.osVersion) >= 26.0) { args.object.viewController.navigationController.interactiveContentPopGestureRecognizer.enabled = false; } diff --git a/apps/demo/src/plugin-demos/canvas.xml b/apps/demo/src/plugin-demos/canvas.xml index a4cedece8..3d3b9625a 100644 --- a/apps/demo/src/plugin-demos/canvas.xml +++ b/apps/demo/src/plugin-demos/canvas.xml @@ -1,10 +1,10 @@ - + - +