Skip to content

Commit 8e4a570

Browse files
committed
Created WebView example.
1 parent 77b8a65 commit 8e4a570

File tree

7 files changed

+284
-0
lines changed

7 files changed

+284
-0
lines changed

UgWebViewControl/Package.swift

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// swift-tools-version:5.3
2+
3+
import PackageDescription
4+
import Foundation
5+
6+
let SCADE_SDK = ProcessInfo.processInfo.environment["SCADE_SDK"] ?? ""
7+
8+
let package = Package(
9+
name: "UgWebViewControl",
10+
platforms: [
11+
.macOS(.v10_14)
12+
],
13+
products: [
14+
.library(
15+
name: "UgWebViewControl",
16+
type: .static,
17+
targets: [
18+
"UgWebViewControl"
19+
]
20+
)
21+
],
22+
dependencies: [
23+
24+
],
25+
targets: [
26+
.target(
27+
name: "UgWebViewControl",
28+
dependencies: [],
29+
exclude: ["main.page"],
30+
swiftSettings: [
31+
.unsafeFlags(["-F", SCADE_SDK], .when(platforms: [.macOS, .iOS])),
32+
.unsafeFlags(["-I", "\(SCADE_SDK)/include"], .when(platforms: [.android])),
33+
]
34+
)
35+
]
36+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import ScadeKit
2+
3+
extension MainPageAdapter {
4+
var webView: SCDWidgetsWebView {
5+
return self.page?.getWidgetByName("webView") as! SCDWidgetsWebView
6+
}
7+
8+
var button: SCDWidgetsButton {
9+
return self.page?.getWidgetByName("button") as! SCDWidgetsButton
10+
}
11+
12+
var button1: SCDWidgetsButton {
13+
return self.page?.getWidgetByName("button1") as! SCDWidgetsButton
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
2+
<xmi:XMI xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmi:version="2.0" xmlns:binding="http://scade.com/sdk/data/binding" xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" xmlns:graphics="http://scade.com/sdk/view/graphics" xmlns:layout="http://scade.com/sdk/layout" xmlns:native="http://scade.com/sdk/view/widgets/native" xmlns:navigation="http://scade.com/lattice/navigation" xmlns:widgets="http://scade.com/sdk/view/widgets">
3+
<widgets:Page name="main">
4+
<minArea width="414" height="736"/>
5+
<location/>
6+
<backgroundColor Red="248" Green="248" Blue="248"/>
7+
<children xsi:type="native:WebView" name="webView">
8+
<location/>
9+
<size width="414" height="636"/>
10+
<layoutData xsi:type="layout:AutoLayoutData">
11+
<constraints sourceAnchor="TOP" targetAnchor="TOP" source="/0/@children.0" target="/0"/>
12+
<constraints source="/0/@children.0" target="/0"/>
13+
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" source="/0/@children.0" target="/0"/>
14+
<constraints sourceAnchor="BOTTOM" targetAnchor="BOTTOM" constant="-100" source="/0/@children.0" target="/0"/>
15+
</layoutData>
16+
</children>
17+
<children xsi:type="widgets:Button" text="Apple Swift Page" name="button" horizontalAlignment="CENTER">
18+
<font fontFamily="ArialMT" size="17">
19+
<color Red="68" Green="106" Blue="179"/>
20+
</font>
21+
<layoutData xsi:type="layout:AutoLayoutData">
22+
<constraints source="/0/@children.1" target="/0"/>
23+
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" source="/0/@children.1" target="/0"/>
24+
<constraints sourceAnchor="BOTTOM" targetAnchor="BOTTOM" source="/0/@children.1" target="/0"/>
25+
<constraints sourceAnchor="HEIGHT" constant="50" source="/0/@children.1"/>
26+
</layoutData>
27+
<location y="686"/>
28+
<size width="414" height="50"/>
29+
<contentSize width="130" height="19"/>
30+
</children>
31+
<children xsi:type="widgets:Button" text="Get title" name="button1" horizontalAlignment="CENTER">
32+
<font fontFamily="ArialMT" size="17">
33+
<color Red="68" Green="106" Blue="179"/>
34+
</font>
35+
<layoutData xsi:type="layout:AutoLayoutData">
36+
<constraints sourceAnchor="TOP" targetAnchor="BOTTOM" source="/0/@children.2" target="/0/@children.0"/>
37+
<constraints source="/0/@children.2" target="/0"/>
38+
<constraints sourceAnchor="RIGHT" targetAnchor="RIGHT" source="/0/@children.2" target="/0"/>
39+
<constraints sourceAnchor="BOTTOM" targetAnchor="TOP" source="/0/@children.2" target="/0/@children.1"/>
40+
<constraints sourceAnchor="HEIGHT" constant="50" source="/0/@children.2"/>
41+
</layoutData>
42+
<location y="636"/>
43+
<size width="414" height="50"/>
44+
<contentSize width="59" height="19"/>
45+
</children>
46+
<layout xsi:type="layout:AutoLayout"/>
47+
<maxArea width="414" height="736"/>
48+
<size width="414" height="736"/>
49+
</widgets:Page>
50+
<binding:BindingModel/>
51+
<navigation:Navigation page="/0"/>
52+
</xmi:XMI>
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import ScadeKit
2+
3+
class MainPageAdapter: SCDLatticePageAdapter {
4+
5+
let webpage = "https://developer.apple.com/reference/webkit/wkwebview"
6+
7+
// page adapter initialization
8+
override func load(_ path: String) {
9+
super.load(path)
10+
11+
// Add event to load page
12+
button.onClick {
13+
_ in self.webView.load(self.webpage)
14+
}
15+
16+
// Add event when page loaded
17+
webView.onLoaded.append(
18+
SCDWidgetsLoadEventHandler {
19+
(ev: SCDWidgetsLoadEvent?) in print("Page Loaded: \(ev!.url)")
20+
})
21+
22+
// Add event when page failed to load
23+
webView.onLoadFailed.append(
24+
SCDWidgetsLoadFailedEventHandler {
25+
(ev: SCDWidgetsLoadFailedEvent?) in print("Page failed to load \(ev?.message)")
26+
})
27+
28+
// Add handler to control loading of page
29+
webView.onShouldLoad.append(
30+
SCDWidgetsShouldLoadEventHandler {
31+
(ev: SCDWidgetsLoadEvent?) in
32+
let rtn = !ev!.url.contains("loadhtmlstring")
33+
print("will load \(ev!.url) : \(rtn)")
34+
return rtn
35+
})
36+
37+
button1.onClick { _ in
38+
self.getTitle()
39+
}
40+
41+
}
42+
43+
func getTitle() {
44+
let javascript = "var x=document.getElementsByTagName(\"title\")[0].text.toString();x"
45+
let processResult = SCDWidgetsWebViewEvalHandler { result in print(result) }
46+
let handleException = SCDWidgetsWebViewEvalHandler { error in print(error) }
47+
// inject javascript
48+
webView.eval(javascript, onSuccess: processResult, onError: handleException)
49+
}
50+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import ScadeKit
2+
3+
class UgWebViewControl: SCDApplication {
4+
5+
let window = SCDLatticeWindow()
6+
let mainAdapter = MainPageAdapter()
7+
8+
override func onFinishLaunching() {
9+
mainAdapter.load("main.page")
10+
mainAdapter.show(view: window)
11+
}
12+
}

UgWebViewControl/build.yaml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
spm:
2+
- url:
3+
from:
4+
path:
5+
branch:
6+
exact:
7+
revision:
8+
search-paths: []
9+
linked-libs: []
10+
11+
search-paths: []
12+
linked-libs: []
13+
14+
ios:
15+
name: UgWebViewControl
16+
id: com.scade.ugwebviewcontrol
17+
device-family: iphone # iphone, ipad or universal
18+
supported-interface-orientations: ['portrait'] # portrait, upside_down, landscape_left or landscape_right
19+
supported-interface-orientationsiPad: ['portrait']
20+
entitlements-file:
21+
app-delegate-file:
22+
export-method: ad-hoc # app-store, enterprise or development
23+
simulator:
24+
os: 12.1
25+
output: UgWebViewControl/.build/ios-simulator
26+
extra-args:
27+
search-paths: []
28+
linked-libs: []
29+
device:
30+
os: 12.1
31+
output: UgWebViewControl/.build/ios-device
32+
product-path: UgWebViewControl/Product/ios-device
33+
extra-args:
34+
search-paths: []
35+
linked-libs: []
36+
mac:
37+
os: 10.11
38+
output: UgWebViewControl/.build/scade-simulator
39+
extra-args:
40+
search-paths: []
41+
linked-libs: []
42+
sign:
43+
provision-profile:
44+
certificate:
45+
icons:
46+
iphone: # or ipad, sizes: 20X20, 29X29, 40X40, 60X60, 76X76, 83.5X83.5
47+
60X60_2X:
48+
76X76_2X:
49+
76X76_3X:
50+
83.5X83.5_2X:
51+
marketing:
52+
1024X1024_1X:
53+
plist:
54+
CFBundleShortVersionString: string# 1.0
55+
CFBundleVersion: string# 1
56+
NSLocationWhenInUseUsageDescription:
57+
NSCameraUsageDescription: Take pictures from camera
58+
NSPhotoLibraryUsageDescription: Choose a photo from your library
59+
60+
android:
61+
name: UgWebViewControl
62+
id: com.scade.ugwebviewcontrol
63+
version-name: 1.0.0
64+
version-code: 1
65+
build-type: Debug
66+
key-store-properties:
67+
google-api-key:
68+
manifest-file:
69+
permissions: []
70+
armeabi-v7a:
71+
output: UgWebViewControl/.build/android-armeabi-v7a
72+
product-path: UgWebViewControl/Product/android-armeabi-v7a
73+
extra-args:
74+
search-paths: []
75+
linked-libs: []
76+
arm64-v8a:
77+
output: UgWebViewControl/.build/android-arm64-v8a
78+
product-path: UgWebViewControl/Product/android-arm64-v8a
79+
extra-args:
80+
search-paths: []
81+
linked-libs: []
82+
x86:
83+
output: UgWebViewControl/.build/android-x86
84+
product-path: UgWebViewControl/Product/android-x86
85+
extra-args:
86+
search-paths: []
87+
linked-libs: []
88+
x86_64:
89+
output: UgWebViewControl/.build/android-x86_64
90+
product-path: UgWebViewControl/Product/android-x86_64
91+
extra-args:
92+
search-paths: []
93+
linked-libs: []
94+
intent-filters:
95+
- action:
96+
scheme:
97+
categories: []
98+
icons:
99+
mdpi:
100+
hdpi:
101+
xhdpi:
102+
xxhdpi:

0 commit comments

Comments
 (0)