Skip to content

Commit

Permalink
1.0.2 publish
Browse files Browse the repository at this point in the history
  • Loading branch information
Kyun-J committed Dec 22, 2021
1 parent 5625c2b commit e9efc9f
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 29 deletions.
2 changes: 1 addition & 1 deletion FlexHybridApp.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
Pod::Spec.new do |spec|

spec.name = "FlexHybridApp"
spec.version = "1.0.1"
spec.version = "1.0.2"
spec.summary = "FlexibleHybridApp-iOS"
spec.ios.deployment_target = '10.0'
spec.swift_version = '5.5.1'
Expand Down
87 changes: 85 additions & 2 deletions README-ko.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
[Android Version](https://github.com/Kyun-J/FlexHybridApp-Android)

[Typescript Support](https://github.com/Kyun-J/FlexHybridApp-Script)

# FlexibleHybrid

FlexibleHybridApp은 Web, Native 상호간의 Interface을 Promise로 구현하는 등, HybridApp을 개발하기 위해 여러 편의 기능을 제공하는 프레임워크 입니다.
WKWebView와 Native간 인터페이스 간소화, 비동기 처리를 비롯하여
WKWebView사용에 여러 편의 기능을 제공하는 라이브러리입니다.

# framework 추가 방법

Expand All @@ -13,4 +17,83 @@ podFile에 다음을 추가

***iOS Deployment Target은 10.0 입니다.***

# 리드미 재 작성중
# Flex 라이브러리 주요 특징

1. [Android 버전]()과 서로 유사한 개발 규칙 및 기능을 가집니다.
2. WKWebView와 Native간의 인터페이스가 비동기적으로 동작합니다.
1. Web에서 **Promise로 호출 및 반환**됩니다.
2. Native에서는 별도의 **Concurrent한 Queue**에서 동작합니다.
3. **Swift Closure**로 인터페이스시 동작을 정의합니다.
4. **Model Object**로 인터페이스 할 수 있습니다.
5. 인터페이스 동작이 가능한 Url을 지정하여, **원하지 않는 사이트에서의 Native호출**을 막을 수 있습니다.

외 여러 기능들 포함

# 인터페이스 기본 사용법

기본적으로 아래와 같은 패턴으로 인터페이스 등록 및 사용이 가능하며,
모든 인터페이스는 비동기적으로 동작합니다.
Web에서는 응답이 발생할 때 까지 **pending상태**가 됩니다.

## Web to Native
### 인터페이스 등록

FlexWebView에 페이지가 로드되기 전 인터페이스를 설정합니다.

```swift
// in swift
flexWebView.setInterface("funcName") { args -> String? in
return "received from web - \(args[0]?.toString() ?? "no value"), return to web - \(100)"
}
flexWebView.load(somUrl)
```

### 인터페이스 사용

```js
// in js
const test = async (req) => {
const res = await $flex.funcName(req);
console.log(res); // received from web - 200, return to web - 100
};
test(200);
```

## Native to Web

### 인터페이스 등록

1. [FlexHybridApp-Script](https://github.com/Kyun-J/FlexHybridApp-Scripts) 적용시

```js
// in js
$flex.web.funcName = async (req) => {
return await new Promise((resolve) => {
setTimeout(() => resolve(`received from web - ${req}`), 100);
});
};
```

2. 미적용시

`window.onFlexLoad` 함수를 통해 $flex 객체가 로드된 후 인터페이스를 등록하여햐 합니다.

```js
// in js
window.onFlexLoad = () => {
$flex.web.funcName = async (req) => {
return await new Promise((resolve) => {
setTimeout(() => resolve(`received from web - ${req}`), 100);
});
};
};
```

### 인터페이스 사용

```swift
// in swift
flexWebView.evalFlexFunc("funcName", "sendData") { response in
print(response.toString()!) // received from web - sendData
}
```
12 changes: 8 additions & 4 deletions framework/flexhybridapp.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

/* Begin PBXBuildFile section */
DF103901247D2F9800B77DFC /* lib in Resources */ = {isa = PBXBuildFile; fileRef = DF103900247D2F9800B77DFC /* lib */; };
DF5F181D2444737D00BE44F4 /* flexhybridapp.h in Headers */ = {isa = PBXBuildFile; fileRef = DF5F181B2444737D00BE44F4 /* flexhybridapp.h */; settings = {ATTRIBUTES = (Public, ); }; };
DF5F1824244473A700BE44F4 /* FlexWebView.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF5F1823244473A700BE44F4 /* FlexWebView.swift */; };
DF8175B3251AD14700BACA91 /* FlexWebView.xib in Resources */ = {isa = PBXBuildFile; fileRef = DF8175B2251AD14700BACA91 /* FlexWebView.xib */; };
DF85F11A25CD22820020C9BE /* FlexEvent.swift in Sources */ = {isa = PBXBuildFile; fileRef = DF85F11925CD22820020C9BE /* FlexEvent.swift */; };
Expand All @@ -29,7 +28,6 @@
/* Begin PBXFileReference section */
DF103900247D2F9800B77DFC /* lib */ = {isa = PBXFileReference; lastKnownFileType = folder; path = lib; sourceTree = "<group>"; };
DF5F18182444737D00BE44F4 /* FlexHybridApp.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = FlexHybridApp.framework; sourceTree = BUILT_PRODUCTS_DIR; };
DF5F181B2444737D00BE44F4 /* flexhybridapp.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = flexhybridapp.h; sourceTree = "<group>"; };
DF5F181C2444737D00BE44F4 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
DF5F1823244473A700BE44F4 /* FlexWebView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = FlexWebView.swift; sourceTree = "<group>"; };
DF8175B2251AD14700BACA91 /* FlexWebView.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = FlexWebView.xib; sourceTree = "<group>"; };
Expand Down Expand Up @@ -80,7 +78,6 @@
children = (
DF103900247D2F9800B77DFC /* lib */,
DFB73CFC24526DA4002B4C4C /* js */,
DF5F181B2444737D00BE44F4 /* flexhybridapp.h */,
DF5F181C2444737D00BE44F4 /* Info.plist */,
DF5F1823244473A700BE44F4 /* FlexWebView.swift */,
DFF4991C274F7B860031E85E /* util */,
Expand Down Expand Up @@ -123,7 +120,6 @@
isa = PBXHeadersBuildPhase;
buildActionMask = 2147483647;
files = (
DF5F181D2444737D00BE44F4 /* flexhybridapp.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -360,12 +356,16 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = app.dvkyun.flexhybridapp;
PRODUCT_NAME = FlexHybridApp;
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SKIP_INSTALL = NO;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
Expand Down Expand Up @@ -393,12 +393,16 @@
"@executable_path/Frameworks",
"@loader_path/Frameworks",
);
MACOSX_DEPLOYMENT_TARGET = 11.0;
MARKETING_VERSION = 1.0.1;
PRODUCT_BUNDLE_IDENTIFIER = app.dvkyun.flexhybridapp;
PRODUCT_NAME = FlexHybridApp;
PROVISIONING_PROFILE_SPECIFIER = "";
SDKROOT = iphoneos;
SKIP_INSTALL = NO;
SUPPORTED_PLATFORMS = "iphonesimulator iphoneos";
SUPPORTS_MACCATALYST = NO;
SUPPORTS_MAC_DESIGNED_FOR_IPHONE_IPAD = NO;
SWIFT_VERSION = 5.0;
TARGETED_DEVICE_FAMILY = "1,2";
};
Expand Down
12 changes: 9 additions & 3 deletions framework/flexhybridapp/FlexWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ open class FlexComponent: NSObject, WKNavigationDelegate, WKScriptMessageHandler
private var baseUrl: String? = nil
private var allowUrlMap: [String: Bool] = [:]
private var recentConfigRuleString: String? = nil
private var applyContentRuleList: Any? = nil

private var showWebViewConsole = true

Expand Down Expand Up @@ -196,7 +197,9 @@ open class FlexComponent: NSObject, WKNavigationDelegate, WKScriptMessageHandler
public func removeAllowUrl(_ urlString: String) {
allowUrlMap.removeValue(forKey: urlString)
if allowUrlMap.count == 0 {
config.userContentController.removeAllContentRuleLists()
if let _applyContentRuleList = applyContentRuleList as? WKContentRuleList {
config.userContentController.remove(_applyContentRuleList)
}
} else {
configAllowContentRule()
}
Expand Down Expand Up @@ -233,11 +236,14 @@ open class FlexComponent: NSObject, WKNavigationDelegate, WKScriptMessageHandler
guard let contentRuleList = contentRuleList else {
return
}

let configuration = self.config

configuration.userContentController.removeAllContentRuleLists()
if let _applyContentRuleList = self.applyContentRuleList as? WKContentRuleList {
configuration.userContentController.remove(_applyContentRuleList)
}
configuration.userContentController.add(contentRuleList)
self.applyContentRuleList = contentRuleList
}
}

Expand Down
19 changes: 0 additions & 19 deletions framework/flexhybridapp/flexhybridapp.h

This file was deleted.

0 comments on commit e9efc9f

Please sign in to comment.