Skip to content

Commit 7058902

Browse files
committed
feat: ios updates
1 parent 93913ae commit 7058902

File tree

32 files changed

+389
-40
lines changed

32 files changed

+389
-40
lines changed

packages/canvas/src-native/canvas-ios/CanvasDemo/CanvasDemo/Base.lproj/Main.storyboard

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17506" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
2+
<document type="com.apple.InterfaceBuilder3.CocoaTouch.Storyboard.XIB" version="3.0" toolsVersion="17701" targetRuntime="iOS.CocoaTouch" propertyAccessControl="none" useAutolayout="YES" useTraitCollections="YES" useSafeAreas="YES" colorMatched="YES" initialViewController="BYZ-38-t0r">
33
<device id="retina6_1" orientation="portrait" appearance="light"/>
44
<dependencies>
55
<deployment identifier="iOS"/>
6-
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17505"/>
6+
<plugIn identifier="com.apple.InterfaceBuilder.IBCocoaTouchPlugin" version="17703"/>
77
<capability name="Safe area layout guides" minToolsVersion="9.0"/>
88
<capability name="System colors in document resources" minToolsVersion="11.0"/>
99
<capability name="documents saved in the Xcode 8 format" minToolsVersion="8.0"/>
@@ -17,9 +17,10 @@
1717
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
1818
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
1919
<subviews>
20-
<view contentMode="scaleToFill" insetsLayoutMarginsFromSafeArea="NO" id="v2e-nc-8cA" customClass="TNSCanvas">
20+
<view contentMode="scaleToFill" preservesSuperviewLayoutMargins="YES" id="v2e-nc-8cA" customClass="TNSCanvas">
2121
<rect key="frame" x="0.0" y="0.0" width="414" height="896"/>
2222
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
23+
<viewLayoutGuide key="safeArea" id="G7H-IE-GiS"/>
2324
<color key="backgroundColor" systemColor="systemBackgroundColor"/>
2425
</view>
2526
<button opaque="NO" contentMode="scaleToFill" fixedFrame="YES" insetsLayoutMarginsFromSafeArea="NO" contentHorizontalAlignment="center" contentVerticalAlignment="center" buttonType="system" lineBreakMode="middleTruncation" translatesAutoresizingMaskIntoConstraints="NO" id="XYS-nI-wVg">

packages/canvas/src-native/canvas-ios/CanvasDemo/CanvasDemo/Info.plist

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@
2020
<string>1</string>
2121
<key>LSRequiresIPhoneOS</key>
2222
<true/>
23+
<key>NSAppTransportSecurity</key>
24+
<dict>
25+
<key>NSAllowsArbitraryLoads</key>
26+
<true/>
27+
</dict>
2328
<key>UILaunchStoryboardName</key>
2429
<string>LaunchScreen</string>
2530
<key>UIMainStoryboardFile</key>

packages/canvas/src-native/canvas-ios/CanvasDemo/CanvasDemo/ViewController.swift

Lines changed: 198 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,156 @@ class ViewController: UIViewController, TNSCanvasListener {
1212
let PI: Float = .pi
1313
let TWO_PI: Float = .pi * 2
1414
var tapped = 0
15-
15+
var svg: TNSSVG?
1616
override func viewDidLoad() {
1717
super.viewDidLoad()
1818
scale = Int(UIScreen.main.scale)
1919
// Do any additional setup after loading the view.
2020
canvas1.setListener(self)
21+
canvas1.isHidden = true
2122
//let matrix = Canvas.createSVGMatrix()
2223
//matrix.a = 3.0
24+
svg = TNSSVG(frame: view.bounds)
25+
canvas1.addSubview(svg!)
26+
svg?.bringSubviewToFront(canvas1)
27+
svg!.backgroundColor = .white
28+
// svg?.src = """
29+
//<svg width="660" height="220" style="outline: 1px solid red">
30+
// <defs>
31+
// <clipPath id="text-2">
32+
// <text x="50" y="133" font-family="Georgia" font-weight="bold" font-size="4px" >Clipping Path</text>
33+
// </clipPath>
34+
// </defs>
35+
//
36+
// <g transform="translate(300 300)" clip-path="url(#text-2)">
37+
// <polygon points="110 10, 660 110, 110,210" fill="#c99" />
38+
// <circle cx="110" cy="110" r="100" fill="#9c6" />
39+
// </g>
40+
//</svg>
41+
//"""
42+
43+
// svg?.src = """
44+
// <svg xmlns="http://www.w3.org/2000/svg">
45+
// <defs>
46+
// <linearGradient id="Gradient1">
47+
// <stop offset="5%" stop-color="white"/>
48+
// <stop offset="95%" stop-color="blue"/>
49+
// </linearGradient>
50+
// <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
51+
// <stop offset="5%" stop-color="red"/>
52+
// <stop offset="95%" stop-color="orange"/>
53+
// </linearGradient>
54+
// <pattern id="Pattern" x="0" y="0" width="1" height="1">
55+
// <rect x="0" y="0" width="50" height="50" fill="skyblue"/>
56+
// <rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
57+
// <circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
58+
// </pattern>
59+
// </defs>
60+
// <rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
61+
// </svg>
62+
// """
63+
64+
65+
/* svg.src = """
66+
<svg width="200" height="200" xmlns="http://www.w3.org/2000/svg">
67+
<defs>
68+
<linearGradient id="Gradient1">
69+
<stop offset="5%" stop-color="white"/>
70+
<stop offset="95%" stop-color="blue"/>
71+
</linearGradient>
72+
<linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
73+
<stop offset="5%" stop-color="red"/>
74+
<stop offset="95%" stop-color="orange"/>
75+
</linearGradient>
76+
<pattern id="Pattern" x="0" y="0" width=".25" height=".25">
77+
<rect x="0" y="0" width="50" height="50" fill="skyblue"/>
78+
<rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
79+
<circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
80+
</pattern>
81+
</defs>
82+
<rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
83+
</svg>
84+
"""*/
85+
86+
// svg.src = """
87+
// <svg viewBox="0 0 230 100" xmlns="http://www.w3.org/2000/svg">
88+
// <defs>
89+
// <pattern fill="red" id="star" viewBox="0,0,10,10" width="10%" height="10%">
90+
// <polygon points="0,0 2,5 0,10 5,8 10,10 8,5 10,0 5,2"/>
91+
// </pattern>
92+
// </defs>
93+
// <circle cx="50" cy="50" r="50" fill="url(#star)"/>
94+
// <circle cx="180" cy="50" r="40" fill="none" stroke-width="20" stroke="url(#star)"/>
95+
// </svg>
96+
// """
97+
98+
// svg.src = """
99+
// <svg viewBox="0 0 80 20" xmlns="http://www.w3.org/2000/svg"
100+
// xmlns:xlink="http://www.w3.org/1999/xlink">
101+
// <!-- Our symbol in its own coordinate system -->
102+
// <symbol id="myDot" width="10" height="10" viewBox="0 0 2 2">
103+
// <circle cx="1" cy="1" r="1" />
104+
// </symbol>
105+
//
106+
// <!-- A grid to materialize our symbol positioning -->
107+
// <path transform="translate(10)" d="M0,10 h80 M10,0 v20 M25,0 v20 M40,0 v20 M55,0 v20 M70,0 v20" fill="none" stroke="pink" />
108+
//
109+
// <!-- All instances of our symbol -->
110+
// <use xlink:href="#myDot" x="5" y="50" style="opacity:1.0" />
111+
// <use xlink:href="#myDot" x="20" y="50" />
112+
// <use xlink:href="#myDot" x="35" y="50" />
113+
// <use xlink:href="#myDot" x="50" y="50" />
114+
// <use xlink:href="#myDot" x="65" y="50" style="opacity:0.2" />
115+
// </svg>
116+
// """
117+
118+
119+
// https://upload.wikimedia.org/wikipedia/commons/4/4c/The_Hague%2C_Netherlands%2C_the_old_city_center.svg
120+
// https://upload.wikimedia.org/wikipedia/commons/6/6c/Trajans-Column-lower-animated.svg
121+
122+
// https://upload.wikimedia.org/wikipedia/commons/b/b1/Cluse_de_Chamb%C3%A9ry_-_Carte_de_l%27occupation_des_sols_%28CORINE%29.svg
123+
124+
125+
//https://upload.wikimedia.org/wikipedia/commons/b/b6/Moldova_%281483%29-en.svg
126+
127+
// https://upload.wikimedia.org/wikipedia/commons/a/a0/Location_map_San_Francisco_Bay_Area.svg // 40mb
128+
129+
// https://upload.wikimedia.org/wikipedia/commons/c/c1/Propane_flame_contours-en.svg
130+
131+
// https://upload.wikimedia.org/wikipedia/commons/9/95/Kaiserstandarte_Version1.svg
132+
133+
// https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/car.svg
134+
135+
// https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/lineargradient1.svg
136+
137+
//http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg
138+
139+
// https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/AJ_Digital_Camera.svg
140+
141+
// https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/tiger.svg
142+
143+
// https://upload.wikimedia.org/wikipedia/commons/f/ff/1_42_polytope_7-cube.svg
144+
145+
// https://upload.wikimedia.org/wikipedia/commons/7/7c/Map_of_the_world_by_the_US_Gov_as_of_2016_no_legend.svg
146+
147+
// https://upload.wikimedia.org/wikipedia/commons/9/9d/The_Rhodopes_on_The_Paths_Of_Orpheus_And_Eurydice_Project_Map.svg
148+
149+
// https://upload.wikimedia.org/wikipedia/commons/1/1c/KINTETSU23000_20140424A.svg
150+
151+
// do{
152+
// let svg_file = NSURL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + "_svg_file.svg")
153+
// let svg_data = try Data(contentsOf: URL(string: "https://dev.w3.org/SVG/tools/svgweb/samples/svg-files/tiger.svg")!)
154+
// try svg_data.write(to: svg_file.absoluteURL!, options: .atomicWrite)
155+
// //let svgContents = String(data: svg_data, encoding: .utf8)
156+
// svg?.srcPath = svg_file.path
157+
// //svg?.src = svgContents
158+
//
159+
// }catch {
160+
// print(error)
161+
// }
162+
163+
164+
23165
}
24166

25167
var drawn = false
@@ -145,6 +287,61 @@ class ViewController: UIViewController, TNSCanvasListener {
145287

146288

147289
func drawAll() {
290+
291+
svg?.src = """
292+
<svg viewBox="0 0 10 10" xmlns="http://www.w3.org/2000/svg"
293+
xmlns:xlink="http://www.w3.org/1999/xlink">
294+
<defs>
295+
<radialGradient id="myGradient">
296+
<stop offset="10%" stop-color="gold" />
297+
<stop offset="95%" stop-color="red" />
298+
</radialGradient>
299+
</defs>
300+
301+
<!-- using my radial gradient -->
302+
<circle transform="scale(10 10)" cx="5" cy="5" r="4" />
303+
</svg>
304+
"""
305+
306+
307+
// do{
308+
// let svg_file = NSURL(fileURLWithPath: NSTemporaryDirectory() + UUID().uuidString + "_svg_file.svg")
309+
// let svg_data = try Data(contentsOf: URL(string: "http://thenewcode.com/assets/images/thumbnails/homer-simpson.svg")!)
310+
// try svg_data.write(to: svg_file.absoluteURL!, options: .atomicWrite)
311+
// //let svgContents = String(data: svg_data, encoding: .utf8)
312+
// svg?.srcPath = svg_file.path
313+
// //svg?.src = svgContents
314+
//
315+
// }catch {
316+
// print(error)
317+
// }
318+
319+
320+
321+
//
322+
// svg?.src = """
323+
// <svg xmlns="http://www.w3.org/2000/svg">
324+
// <defs>
325+
// <linearGradient id="Gradient1">
326+
// <stop offset="5%" stop-color="white"/>
327+
// <stop offset="95%" stop-color="blue"/>
328+
// </linearGradient>
329+
// <linearGradient id="Gradient2" x1="0" x2="0" y1="0" y2="1">
330+
// <stop offset="5%" stop-color="red"/>
331+
// <stop offset="95%" stop-color="orange"/>
332+
// </linearGradient>
333+
// <pattern id="Pattern" x="0" y="0" width=".25" height=".25">
334+
// <rect x="0" y="0" width="50" height="50" fill="skyblue"/>
335+
// <rect x="0" y="0" width="25" height="25" fill="url(#Gradient2)"/>
336+
// <circle cx="25" cy="25" r="20" fill="url(#Gradient1)" fill-opacity="0.5"/>
337+
// </pattern>
338+
// </defs>
339+
// <rect fill="url(#Pattern)" stroke="black" width="200" height="200"/>
340+
// </svg>
341+
// """
342+
343+
344+
148345
// let gl = self.canvas1?.getContext("webgl2") as! TNSWebGLRenderingContext
149346
//canvas1?.handleInvalidationManually = true
150347

packages/canvas/src-native/canvas-ios/CanvasNative.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88

99
/* Begin PBXBuildFile section */
1010
F107B96E255AE5850094FC51 /* TNSFillRule.swift in Sources */ = {isa = PBXBuildFile; fileRef = F107B96D255AE5850094FC51 /* TNSFillRule.swift */; };
11+
F11A1ABB25C238F100E60484 /* TNSSVG.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11A1ABA25C238F100E60484 /* TNSSVG.swift */; };
1112
F11A7431255930590038B4C6 /* TNSTextDirection.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11A7430255930590038B4C6 /* TNSTextDirection.swift */; };
1213
F11C5D142524403700538D04 /* CanvasNative.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F11C5D0A2524403700538D04 /* CanvasNative.framework */; };
1314
F11C5D192524403700538D04 /* CanvasNativeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = F11C5D182524403700538D04 /* CanvasNativeTests.swift */; };
1415
F11C5D1B2524403700538D04 /* CanvasNative.h in Headers */ = {isa = PBXBuildFile; fileRef = F11C5D0D2524403700538D04 /* CanvasNative.h */; settings = {ATTRIBUTES = (Public, ); }; };
1516
F1A87B25255BB4F000394387 /* TextBaseLine.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1A87B24255BB4F000394387 /* TextBaseLine.swift */; };
1617
F1A87C75255D00BA00394387 /* TNSCanvas.xib in Resources */ = {isa = PBXBuildFile; fileRef = F1A87C74255D00BA00394387 /* TNSCanvas.xib */; };
18+
F1DE2E4F2612F7CA0000D48F /* Utils.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1DE2E4E2612F7CA0000D48F /* Utils.swift */; };
1719
F1FF6A6A25248CFF001DAE0D /* TNSDOMMatrix.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FF6A3225248CFE001DAE0D /* TNSDOMMatrix.swift */; };
1820
F1FF6A6B25248CFF001DAE0D /* TNSTextAlignment.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FF6A3325248CFE001DAE0D /* TNSTextAlignment.swift */; };
1921
F1FF6A6C25248CFF001DAE0D /* TNSCanvasListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = F1FF6A3425248CFE001DAE0D /* TNSCanvasListener.swift */; };
@@ -83,6 +85,7 @@
8385

8486
/* Begin PBXFileReference section */
8587
F107B96D255AE5850094FC51 /* TNSFillRule.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TNSFillRule.swift; sourceTree = "<group>"; };
88+
F11A1ABA25C238F100E60484 /* TNSSVG.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TNSSVG.swift; path = CanvasNative/Source/TNSSVG.swift; sourceTree = "<group>"; };
8689
F11A7430255930590038B4C6 /* TNSTextDirection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TNSTextDirection.swift; sourceTree = "<group>"; };
8790
F11C5D0A2524403700538D04 /* CanvasNative.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = CanvasNative.framework; sourceTree = BUILT_PRODUCTS_DIR; };
8891
F11C5D0D2524403700538D04 /* CanvasNative.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = CanvasNative.h; sourceTree = "<group>"; };
@@ -92,6 +95,7 @@
9295
F11C5D1A2524403700538D04 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
9396
F1A87B24255BB4F000394387 /* TextBaseLine.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TextBaseLine.swift; sourceTree = "<group>"; };
9497
F1A87C74255D00BA00394387 /* TNSCanvas.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = TNSCanvas.xib; sourceTree = "<group>"; };
98+
F1DE2E4E2612F7CA0000D48F /* Utils.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Utils.swift; sourceTree = "<group>"; };
9599
F1FF6A3225248CFE001DAE0D /* TNSDOMMatrix.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TNSDOMMatrix.swift; path = CanvasNative/Source/TNSDOMMatrix.swift; sourceTree = "<group>"; };
96100
F1FF6A3325248CFE001DAE0D /* TNSTextAlignment.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TNSTextAlignment.swift; path = CanvasNative/Source/TNSTextAlignment.swift; sourceTree = "<group>"; };
97101
F1FF6A3425248CFE001DAE0D /* TNSCanvasListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; name = TNSCanvasListener.swift; path = CanvasNative/Source/TNSCanvasListener.swift; sourceTree = "<group>"; };
@@ -199,6 +203,8 @@
199203
F11C5D002524403700538D04 = {
200204
isa = PBXGroup;
201205
children = (
206+
F1DE2E4E2612F7CA0000D48F /* Utils.swift */,
207+
F11A1ABA25C238F100E60484 /* TNSSVG.swift */,
202208
F1A87C74255D00BA00394387 /* TNSCanvas.xib */,
203209
F1A87B24255BB4F000394387 /* TextBaseLine.swift */,
204210
F107B96D255AE5850094FC51 /* TNSFillRule.swift */,
@@ -438,10 +444,12 @@
438444
F1FF6A8725248CFF001DAE0D /* TNS_OES_texture_half_float.swift in Sources */,
439445
F1FF6A8825248CFF001DAE0D /* TNSTextDecoder.swift in Sources */,
440446
F1FF6A8925248CFF001DAE0D /* TNSWebGLActiveInfo.swift in Sources */,
447+
F11A1ABB25C238F100E60484 /* TNSSVG.swift in Sources */,
441448
F1FF6A8A25248CFF001DAE0D /* TNSWebGLRenderingContext.swift in Sources */,
442449
F1FF6A8B25248CFF001DAE0D /* HowToClear.swift in Sources */,
443450
F1FF6A8C25248CFF001DAE0D /* TNS_OES_fbo_render_mipmap.swift in Sources */,
444451
F1FF6A8D25248CFF001DAE0D /* TNSImageSmoothingQuality.swift in Sources */,
452+
F1DE2E4F2612F7CA0000D48F /* Utils.swift in Sources */,
445453
F1FF6A8E25248CFF001DAE0D /* TNSWebGLShaderPrecisionFormat.swift in Sources */,
446454
F1FF6A8F25248CFF001DAE0D /* TNS_OES_texture_half_float_linear.swift in Sources */,
447455
F1FF6A9025248CFF001DAE0D /* TNS_OES_texture_float_linear.swift in Sources */,

0 commit comments

Comments
 (0)