Skip to content

Commit

Permalink
before 1.0.1 publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyun-J committed Dec 13, 2021
1 parent 8d2df6e commit f780ea6
Show file tree
Hide file tree
Showing 23 changed files with 5,841 additions and 4,932 deletions.
8 changes: 6 additions & 2 deletions demo/flex-demo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
DF479DFD253578CB00478776 /* frame.html in Resources */ = {isa = PBXBuildFile; fileRef = DF479DFC253578CB00478776 /* frame.html */; };
DFCEB8A624F8C79300C2CE3D /* FlexHybridApp.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = DFCEB8A524F8C79300C2CE3D /* FlexHybridApp.framework */; };
DFCEB8A724F8C79300C2CE3D /* FlexHybridApp.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = DFCEB8A524F8C79300C2CE3D /* FlexHybridApp.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
DFE3C37F2766E826000DFF28 /* Models.swift in Sources */ = {isa = PBXBuildFile; fileRef = DFE3C37E2766E825000DFF28 /* Models.swift */; };
/* End PBXBuildFile section */

/* Begin PBXCopyFilesBuildPhase section */
Expand Down Expand Up @@ -45,6 +46,7 @@
291A5276245D598000558FE8 /* test.html */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.html; path = test.html; sourceTree = "<group>"; };
DF479DFC253578CB00478776 /* frame.html */ = {isa = PBXFileReference; lastKnownFileType = text.html; path = frame.html; sourceTree = "<group>"; };
DFCEB8A524F8C79300C2CE3D /* FlexHybridApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = FlexHybridApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DFE3C37E2766E825000DFF28 /* Models.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Models.swift; sourceTree = "<group>"; };
DFFBBCD3248F6E6600762A31 /* FlexHybridApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; path = FlexHybridApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -89,6 +91,7 @@
291A525F245C369E00558FE8 /* Assets.xcassets */,
291A5261245C369E00558FE8 /* LaunchScreen.storyboard */,
291A5264245C369E00558FE8 /* Info.plist */,
DFE3C37E2766E825000DFF28 /* Models.swift */,
);
path = "flex-demo";
sourceTree = "<group>";
Expand Down Expand Up @@ -178,6 +181,7 @@
291A525B245C369D00558FE8 /* ViewController.swift in Sources */,
291A5257245C369D00558FE8 /* AppDelegate.swift in Sources */,
291A5259245C369D00558FE8 /* SceneDelegate.swift in Sources */,
DFE3C37F2766E826000DFF28 /* Models.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -253,7 +257,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -307,7 +311,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 14.0;
IPHONEOS_DEPLOYMENT_TARGET = 15.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = iphoneos;
Expand Down
24 changes: 24 additions & 0 deletions demo/flex-demo/Models.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// Models.swift
// flex-demo
//
// Created by 황견주 on 2021/12/13.
//

import Foundation


struct TestModel1: Codable {
var string: String
var integer: Int
}

struct TestModel2: Codable {
var array: [String]
var dic: [String: String]
var model: TestModel3
}

struct TestModel3: Codable {
var bool: Bool
}
71 changes: 50 additions & 21 deletions demo/flex-demo/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@ class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHan
enum TestError: Error {
case test
}

let testReceive = FlexClosure.array { (arguments) -> Array<Any?>? in
let testReceive = FlexClosure.interface { (arguments) in
let data = arguments[0].asDictionary()!
let dicData: [String:FlexData] = data["d2"]!.reified()!
print("\(data["d1"]!.asInt()!) \(String(describing: dicData["data"]?.toString()))")
print("\(data["d1"]!.asInt()!) \(String(describing: dicData["data"]!.toString()))")
var returnValue: [Any?] = []
returnValue.append(10)
returnValue.append(24123.54235234)
Expand All @@ -44,15 +44,16 @@ class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHan
returnValue["key1"] = "value1\ntest"
returnValue["key2"] = dictionaryValue
returnValue["key3"] = ["arrayValue1",nil]
returnValue["key4"] = true
// Promise return to Web
// PromiseReturn can be called at any time.
action.promiseReturn(returnValue)
}

override func viewDidLoad() {
super.viewDidLoad()

component.addEventListener { (type, funcName, url) in
component.addEventListener { (type, funcName, url, msg) in
var typeTxt = "";
if type == FlexEvent.SUCCESS {
typeTxt = "SUCCESS"
Expand All @@ -63,60 +64,88 @@ class ViewController: UIViewController, WKNavigationDelegate, WKScriptMessageHan
} else if type == FlexEvent.INIT {
typeTxt = "INIT"
}
print("EVENT --------- \(typeTxt)")
print("\nEVENT --------- \(typeTxt)")
print("FUNCTUIN ------ $flex.\(funcName)")
print("URL ----------- \(url)")
// print("URL ----------- \(url)")
print("MSG ----------- \(msg ?? "nil")\n")
}

// add js interface
component.intInterface("test1")
{ (arguments) -> Int in
component.setInterface("test1")
{ (arguments) in
// code works in background...
return arguments[0].asInt()! + 1
}
component.voidInterface("test2")
{ (arguments) -> Void in
component.setInterface("test2")
{ (arguments) in
// code works in background...

// call $flex.web function
// same as $flex.web.help("Help me Flex!") in js
self.mWebView.evalFlexFunc("help", sendData: "Help me Flex!")
{ (value) -> Void in
{ (value) in
// Retrun from $flex.web.help func
let arr = value.asArray()!
let data1: String = arr[0].reified()!
let data2: String? = arr[1].reified()
let data2: Bool = arr[1].reified()!
print("Web Func Retrun ---------------")
print("\(data1) \(data2 ?? "this is null")")
print("\(data1) \(data2)")
print("-------------------------------")
}
}

component.arrayInterface("testReceive", testReceive)
component.setInterface("testReceive", nil, testReceive)

// add FlexAction
component.setAction("testAction", testAction)
component.setAction("testAction", nil, testAction)

// test JS Reject
component.dictionaryInterface("testReject1")
{ arguemnts -> Dictionary<String,Any?> in
component.setInterface("testReject1")
{ arguemnts in
throw TestError.test
}

component.setAction("testReject2")
{ (action, arguemnts) -> Void in
{ (action, arguemnts) in
action.reject()
}

component.setAction("modelTest1")
{ (action, model: TestModel1?) in
print("Model Test 1 ------------")
print("\(String(describing: model?.string)) \(String(describing: model?.integer))")
print("-------------------------")
action.promiseReturn()
}

component.setInterface("modelTest2")
{ (model: TestModel2?) -> Void in
print("Model Test 2 ------------")
print("\(String(describing: model?.array)) \(String(describing: model?.dic))")
print("\(String(describing: model?.model.bool))")
print("-------------------------")
}

// component.setInterface("modelTest3")
// { arguments -> TestModel2 in
// return TestModel2(array: ["test1"], dic: ["test2": "test3"], model: TestModel3(bool: true))
// }

component.setAction("modelTest3")
{ (action, arguments) in
action.promiseReturn(TestModel2(array: ["test1"], dic: ["test2": "test3"], model: TestModel3(bool: true)))
}

component.evalFlexFunc("directTest") { value -> Void in
print("dirct test suc!!")
}

// setBaseUrl
component.setBaseUrl("file://")
component.setInterfaceTimeout(0)
component.setFlexOnloadWait(0)
// component.setFlexOnloadWait(0)
component.setAllowsUrlAccessInFile(true)
component.setShowWebViewConsole(true)

mWebView = FlexWebView(frame: self.view.frame, component: component)

Expand Down
52 changes: 37 additions & 15 deletions demo/flex-demo/test.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta charset="UTF-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, minimal-ui,, viewport-fit=cover, user-scalable=no"
/>
<script type="application/javascript" src="https://unpkg.com/vconsole/dist/vconsole.min.js"></script>
<script
type="application/javascript"
src="https://cdn.jsdelivr.net/npm/flex-hybrid-app-scripts@0.0.2/dist/script.min.js"
></script>
</head>
<script type="text/javascript">
let t = 0;
Expand All @@ -16,7 +25,7 @@
}
const t3 = async () => {
const z = await $flex.testAction();
console.log(z); // {key1: "value1", key2: {subkey2: 1000.1, subkey1: ["dictionaryValue", 0.12]}, key3: ["arrayValue1", 100]}
console.log(z); // {key1: "value1", key2: {subkey2: 1000.1, subkey1: ["dictionaryValue", 0.12]}, key3: ["arrayValue1", null], key4: true}
console.log(typeof z) // Object
}
const t4 = async () => {
Expand All @@ -39,25 +48,38 @@
const z = await $flex.testReceive({ "d1": 10, "d2": { "data": true } });
console.log(z);
}
const t7 = async () => {
await $flex.modelTest1({ string: "string test", integer: 0 });
}
const t8 = async () => {
await $flex.modelTest2({ array: ["array"], dic: { dic: "dictionary" }, model: { bool: false } });
}
const t9 = async () => {
const z = await $flex.modelTest3();
console.log(z);
}
$flex.web.help = function(data) {
console.log('Received by Native ---- ' + String(data));
return Promise.resolve(['Thanks Flex!', false])
}
$flex.web.directTest = () => {
console.log('direct test!!!!');
}
// when $flex on ready.....
window.onFlexLoad = function() {
console.log('Flex Load Success!!');
$flex.web.help = function(data) {
console.log('Received by Native ---- ' + String(data));
return Promise.resolve(['Thanks Flex!', false])
}
$flex.web.directTest = () => {
console.log('direct test!!!!');
}
}
</script>
<body style="width: 100%; height: 450px;">
<button onclick='t1()' style="width: 100%; height: 150px;">test1</button>
<button onclick='t2()' style="width: 100%; height: 150px;">test2</button>
<button onclick='t3()' style="width: 100%; height: 150px;">testAction</button>
<button onclick='t4()' style="width: 100%; height: 150px;">testReject1</button>
<button onclick='t5()' style="width: 100%; height: 150px;">testReject2</button>
<button onclick='t6()' style="width: 100%; height: 150px;">testReceive</button>
<button onclick='t1()' style="width: 100%; height: 50px;">test1</button>
<button onclick='t2()' style="width: 100%; height: 50px;">test2</button>
<button onclick='t3()' style="width: 100%; height: 50px;">testAction</button>
<button onclick='t4()' style="width: 100%; height: 50px;">testReject1</button>
<button onclick='t5()' style="width: 100%; height: 50px;">testReject2</button>
<button onclick='t6()' style="width: 100%; height: 50px;">testReceive</button>
<button onclick='t7()' style="width: 100%; height: 50px;">modelTest1</button>
<button onclick='t8()' style="width: 100%; height: 50px;">modelTest2</button>
<button onclick='t9()' style="width: 100%; height: 50px;">modelTest3</button>
<iframe src="./frame.html"></iframe>
</body>
</html>
Expand Down
Loading

0 comments on commit f780ea6

Please sign in to comment.