iOS: support swift plugin and library
This commit is contained in:
28
doric-iOS/Example/Example/DemoSwiftLibrary.swift
Normal file
28
doric-iOS/Example/Example/DemoSwiftLibrary.swift
Normal file
@@ -0,0 +1,28 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2023/7/7.
|
||||
// Copyright (c) 2023 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
import Foundation
|
||||
|
||||
class DemoSwiftPlugin: DoricNativePlugin {
|
||||
@objc func test() {
|
||||
print("Here at test")
|
||||
}
|
||||
|
||||
@objc func testData(data: String) {
|
||||
print("Here at test, data is " + data)
|
||||
}
|
||||
|
||||
@objc func testReturn(data: String,promise: DoricPromise) {
|
||||
print("Here at test, promise ")
|
||||
promise.resolve("This is from native")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class DemoSwiftLibrary: DoricLibrary {
|
||||
override func load(_ registry: DoricRegistry!) {
|
||||
registry.registerNativePlugin(DemoSwiftPlugin.self, withName: "demoSwift");
|
||||
}
|
||||
}
|
38
doric-iOS/Example/Example/DemoVC.swift
Normal file
38
doric-iOS/Example/Example/DemoVC.swift
Normal file
@@ -0,0 +1,38 @@
|
||||
//
|
||||
// DemoVC.swift
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2023/7/7.
|
||||
// Copyright © 2023 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
|
||||
import UIKit
|
||||
|
||||
class DemoVC: UIViewController {
|
||||
let filePath: String
|
||||
|
||||
@objc init(path: String) {
|
||||
filePath = path;
|
||||
super.init(nibName: nil, bundle: nil)
|
||||
|
||||
}
|
||||
|
||||
required init?(coder: NSCoder) {
|
||||
filePath = "";
|
||||
super.init(coder: coder)
|
||||
}
|
||||
|
||||
override func viewDidLoad() {
|
||||
super.viewDidLoad();
|
||||
title = filePath;
|
||||
view.backgroundColor = UIColor.white;
|
||||
let jsContent = try? String(contentsOfFile: Bundle.main.bundlePath + "/src/" + filePath,
|
||||
encoding: String.Encoding.utf8)
|
||||
let doricPanel = DoricPanel()
|
||||
doricPanel.view.width = view.width
|
||||
doricPanel.view.height = view.height
|
||||
view.addSubview(doricPanel.view)
|
||||
addChild(doricPanel)
|
||||
doricPanel.config(jsContent, alias: filePath, extra: nil)
|
||||
}
|
||||
}
|
8
doric-iOS/Example/Example/Example-Bridging-Header.h
Normal file
8
doric-iOS/Example/Example/Example-Bridging-Header.h
Normal file
@@ -0,0 +1,8 @@
|
||||
//
|
||||
// Example-Bridging-Header.h
|
||||
// Example
|
||||
//
|
||||
// Created by pengfei.zhou on 2023/7/7.
|
||||
// Copyright © 2023 pengfei.zhou. All rights reserved.
|
||||
//
|
||||
#import <DoricCore/Doric.h>
|
@@ -13,6 +13,7 @@
|
||||
#import "DoricPanelListViewController.h"
|
||||
#import "DoricEmbeddedExampleVC.h"
|
||||
#import "DemoSSRVC.h"
|
||||
#import "Doric_Playground-Swift.h"
|
||||
|
||||
@interface ViewController () <UITableViewDelegate, UITableViewDataSource>
|
||||
@property(nonatomic, copy) NSArray <NSString *> *demoFilePaths;
|
||||
@@ -44,6 +45,7 @@ - (void)viewDidLoad {
|
||||
self.demoFilePaths = tmp;
|
||||
|
||||
[Doric registerLibrary:[DemoLibrary new]];
|
||||
[Doric registerLibrary:[DemoSwiftLibrary new]];
|
||||
[Doric enablePerformance:YES];
|
||||
[Doric enableRenderSnapshot:YES];
|
||||
|
||||
@@ -118,11 +120,12 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
|
||||
DemoSSRVC *vc = [[DemoSSRVC alloc] initWithPath:file];
|
||||
[self.navigationController pushViewController:vc animated:NO];
|
||||
} else {
|
||||
DoricViewController *doricViewController = [[DoricViewController alloc]
|
||||
initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
|
||||
alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row]
|
||||
extra:nil
|
||||
];
|
||||
DemoVC *doricViewController = [[DemoVC alloc] initWithPath:file];
|
||||
// DemoVC *doricViewController = [[DemoVC alloc]
|
||||
// initWithSource:[NSString stringWithFormat:@"assets://src/%@", file]
|
||||
// alias:@"__dev__"//self.demoFilePaths[(NSUInteger) indexPath.row]
|
||||
// extra:nil
|
||||
// ];
|
||||
UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithTitle:@"Devkit" style:UIBarButtonItemStylePlain target:self action:@selector(onOpenDevkit)];
|
||||
doricViewController.navigationItem.rightBarButtonItem = rightBarItem;
|
||||
[self.navigationController pushViewController:doricViewController animated:NO];
|
||||
|
Reference in New Issue
Block a user