iOS support internal class
This commit is contained in:
parent
4df7df1327
commit
821cb1823c
@ -57,7 +57,7 @@ public class DoricJSLoaderManager {
|
||||
|
||||
public AsyncResult<String> loadJSBundle(String source) {
|
||||
if (!TextUtils.isEmpty(source)) {
|
||||
if (source.startsWith("_internal_")) {
|
||||
if (source.startsWith("_internal_://")) {
|
||||
Uri uri = Uri.parse(source);
|
||||
String srcContextId = uri.getQueryParameter("context");
|
||||
String className = uri.getQueryParameter("class");
|
||||
|
@ -45,7 +45,7 @@ class CounterVM extends ViewModel<CountModel, CounterView> {
|
||||
}
|
||||
|
||||
@Entry
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
export class CounterPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
|
||||
getViewHolderClass() {
|
||||
|
@ -1,77 +1,16 @@
|
||||
import { Group, Panel, navbar, text, gravity, Color, LayoutSpec, vlayout, Gravity, hlayout, scroller, layoutConfig, image, modal, navigator, ViewHolder, Text, ViewModel, VMPanel } from "doric";
|
||||
import { title, label, colors } from "./utils";
|
||||
import { ModalDemo } from "./ModalDemo";
|
||||
import { CounterPage } from './Counter'
|
||||
|
||||
interface CountModel {
|
||||
count: number
|
||||
}
|
||||
class CounterView extends ViewHolder {
|
||||
number!: Text
|
||||
counter!: Text
|
||||
build(root: Group) {
|
||||
vlayout(
|
||||
[
|
||||
text({
|
||||
textSize: 40,
|
||||
tag: "tvNumber"
|
||||
}),
|
||||
|
||||
text({
|
||||
text: "Click To Count 1",
|
||||
textSize: 20,
|
||||
tag: "tvCounter"
|
||||
}),
|
||||
],
|
||||
{
|
||||
layoutConfig: layoutConfig().most(),
|
||||
gravity: Gravity.Center,
|
||||
space: 20,
|
||||
}
|
||||
).in(root)
|
||||
this.number = root.findViewByTag("tvNumber")!
|
||||
this.counter = root.findViewByTag("tvCounter")!
|
||||
}
|
||||
}
|
||||
|
||||
class CounterVM extends ViewModel<CountModel, CounterView> {
|
||||
onAttached(s: CountModel, vh: CounterView) {
|
||||
vh.counter.onClick = () => {
|
||||
this.updateState(state => {
|
||||
state.count++
|
||||
})
|
||||
}
|
||||
}
|
||||
onBind(s: CountModel, vh: CounterView) {
|
||||
vh.number.text = `${s.count}`
|
||||
}
|
||||
}
|
||||
|
||||
class MyPage extends VMPanel<CountModel, CounterView>{
|
||||
|
||||
|
||||
getViewHolderClass() {
|
||||
return CounterView
|
||||
}
|
||||
|
||||
getViewModelClass() {
|
||||
return CounterVM
|
||||
}
|
||||
|
||||
getState(): CountModel {
|
||||
return {
|
||||
count: 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Entry(exports = [ModalDemo, MyPage])
|
||||
@Entry(exports = [ModalDemo, CounterPage])
|
||||
class MultiPanelDemo extends Panel {
|
||||
build(rootView: Group): void {
|
||||
scroller(
|
||||
vlayout(
|
||||
[
|
||||
title("Multi Panel"),
|
||||
label('isHidden').apply({
|
||||
label('ModalDemo').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
backgroundColor: colors[0],
|
||||
@ -82,6 +21,17 @@ class MultiPanelDemo extends Panel {
|
||||
navigator(context).push(ModalDemo)
|
||||
}
|
||||
}),
|
||||
label('Counter').apply({
|
||||
width: 200,
|
||||
height: 50,
|
||||
backgroundColor: colors[0],
|
||||
textSize: 30,
|
||||
textColor: Color.WHITE,
|
||||
layoutConfig: layoutConfig().just(),
|
||||
onClick: () => {
|
||||
navigator(context).push(CounterPage)
|
||||
}
|
||||
}),
|
||||
],
|
||||
{
|
||||
layoutConfig: layoutConfig().most().configHeight(LayoutSpec.FIT),
|
||||
|
@ -57,6 +57,28 @@ - (void)addJSLoader:(id <DoricLoaderProtocol>)loader {
|
||||
|
||||
- (DoricAsyncResult <NSString *> *)request:(NSString *)source {
|
||||
__block DoricAsyncResult *ret;
|
||||
if ([source hasPrefix:@"_internal_://"]) {
|
||||
ret = [DoricAsyncResult new];
|
||||
__block NSString *contextId = nil;
|
||||
__block NSString *className = nil;
|
||||
NSURLComponents *components = [NSURLComponents componentsWithString:source];
|
||||
[components.queryItems forEach:^(NSURLQueryItem *obj) {
|
||||
if ([obj.name isEqualToString:@"class"]) {
|
||||
className = obj.value;
|
||||
} else if ([obj.name isEqualToString:@"context"]) {
|
||||
contextId = obj.value;
|
||||
}
|
||||
}];
|
||||
if (contextId && className) {
|
||||
[ret setupResult:[NSString stringWithFormat:@"Entry('%@','%@')", contextId, className]];
|
||||
} else {
|
||||
[ret setupError:[NSException exceptionWithName:@"LoadingError"
|
||||
reason:[NSString stringWithFormat:@"Scheme %@ format error", source]
|
||||
userInfo:nil]];
|
||||
}
|
||||
return ret;
|
||||
|
||||
}
|
||||
[self.loaders enumerateObjectsUsingBlock:^(id <DoricLoaderProtocol> obj, BOOL *stop) {
|
||||
if ([obj filter:source]) {
|
||||
ret = [obj request:source];
|
||||
|
@ -2959,12 +2959,15 @@ function navbar(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function internalScheme(context, panelClass) {
|
||||
return "_internal_://export?class=" + encodeURIComponent(panelClass.name) + "&context=" + context.id;
|
||||
}
|
||||
function navigator(context) {
|
||||
var moduleName = "navigator";
|
||||
return {
|
||||
push: function (source, config) {
|
||||
if (typeof source === 'function') {
|
||||
source = "_internal_://export?class=" + encodeURIComponent(source.name) + "&context=" + context.id;
|
||||
source = internalScheme(context, source);
|
||||
}
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
@ -3536,6 +3539,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.image = image;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.layoutConfig = layoutConfig;
|
||||
exports.list = list;
|
||||
exports.listItem = listItem;
|
||||
|
@ -2291,12 +2291,15 @@ function navbar(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function internalScheme(context, panelClass) {
|
||||
return `_internal_://export?class=${encodeURIComponent(panelClass.name)}&context=${context.id}`;
|
||||
}
|
||||
function navigator(context) {
|
||||
const moduleName = "navigator";
|
||||
return {
|
||||
push: (source, config) => {
|
||||
if (typeof source === 'function') {
|
||||
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
|
||||
source = internalScheme(context, source);
|
||||
}
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
@ -2754,6 +2757,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.image = image;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.layoutConfig = layoutConfig;
|
||||
exports.list = list;
|
||||
exports.listItem = listItem;
|
||||
|
@ -3786,12 +3786,15 @@ function navbar(context) {
|
||||
};
|
||||
}
|
||||
|
||||
function internalScheme(context, panelClass) {
|
||||
return `_internal_://export?class=${encodeURIComponent(panelClass.name)}&context=${context.id}`;
|
||||
}
|
||||
function navigator(context) {
|
||||
const moduleName = "navigator";
|
||||
return {
|
||||
push: (source, config) => {
|
||||
if (typeof source === 'function') {
|
||||
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
|
||||
source = internalScheme(context, source);
|
||||
}
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
@ -4384,6 +4387,7 @@ exports.gravity = gravity;
|
||||
exports.hlayout = hlayout;
|
||||
exports.image = image;
|
||||
exports.input = input;
|
||||
exports.internalScheme = internalScheme;
|
||||
exports.layoutConfig = layoutConfig;
|
||||
exports.list = list;
|
||||
exports.listItem = listItem;
|
||||
|
1
doric-js/index.d.ts
vendored
1
doric-js/index.d.ts
vendored
@ -842,6 +842,7 @@ declare module 'doric/lib/src/native/navigator' {
|
||||
import { BridgeContext } from "doric/lib/src/runtime/global";
|
||||
import { ClassType } from "doric/lib/src/pattern/mvvm";
|
||||
import { Panel } from "doric/lib/src/ui/panel";
|
||||
export function internalScheme(context: BridgeContext, panelClass: ClassType<Panel>): string;
|
||||
export function navigator(context: BridgeContext): {
|
||||
push: (source: string | ClassType<Panel>, config?: {
|
||||
alias?: string | undefined;
|
||||
|
1
doric-js/lib/src/native/navigator.d.ts
vendored
1
doric-js/lib/src/native/navigator.d.ts
vendored
@ -1,6 +1,7 @@
|
||||
import { BridgeContext } from "../runtime/global";
|
||||
import { ClassType } from "../pattern/mvvm";
|
||||
import { Panel } from "../ui/panel";
|
||||
export declare function internalScheme(context: BridgeContext, panelClass: ClassType<Panel>): string;
|
||||
export declare function navigator(context: BridgeContext): {
|
||||
push: (source: string | ClassType<Panel>, config?: {
|
||||
alias?: string | undefined;
|
||||
|
@ -1,9 +1,12 @@
|
||||
export function internalScheme(context, panelClass) {
|
||||
return `_internal_://export?class=${encodeURIComponent(panelClass.name)}&context=${context.id}`;
|
||||
}
|
||||
export function navigator(context) {
|
||||
const moduleName = "navigator";
|
||||
return {
|
||||
push: (source, config) => {
|
||||
if (typeof source === 'function') {
|
||||
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`;
|
||||
source = internalScheme(context, source);
|
||||
}
|
||||
if (config && config.extra) {
|
||||
config.extra = JSON.stringify(config.extra);
|
||||
|
@ -17,6 +17,10 @@ import { BridgeContext } from "../runtime/global"
|
||||
import { ClassType } from "../pattern/mvvm"
|
||||
import { Panel } from "../ui/panel"
|
||||
|
||||
export function internalScheme(context: BridgeContext, panelClass: ClassType<Panel>) {
|
||||
return `_internal_://export?class=${encodeURIComponent(panelClass.name)}&context=${context.id}`
|
||||
}
|
||||
|
||||
export function navigator(context: BridgeContext) {
|
||||
const moduleName = "navigator"
|
||||
return {
|
||||
@ -27,7 +31,7 @@ export function navigator(context: BridgeContext) {
|
||||
singlePage?: boolean,
|
||||
}) => {
|
||||
if (typeof source === 'function') {
|
||||
source = `_internal_://export?class=${encodeURIComponent(source.name)}&context=${context.id}`
|
||||
source = internalScheme(context, source)
|
||||
}
|
||||
if (config && config.extra) {
|
||||
(config as any).extra = JSON.stringify(config.extra)
|
||||
|
Reference in New Issue
Block a user