feat: enhance plugin navigator,add popSelf and popToRoot
This commit is contained in:
parent
864ffa0de7
commit
4da1f3be9d
@ -16,6 +16,7 @@
|
|||||||
package pub.doric.plugin;
|
package pub.doric.plugin;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
|
|
||||||
import com.github.pengfeizhou.jscore.ArchiveException;
|
import com.github.pengfeizhou.jscore.ArchiveException;
|
||||||
@ -114,4 +115,24 @@ public class NavigatorPlugin extends DoricJavaPlugin {
|
|||||||
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
promise.reject(new JavaValue(e.getLocalizedMessage()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@DoricMethod(thread = ThreadMode.UI)
|
||||||
|
public void popSelf(DoricPromise promise) {
|
||||||
|
IDoricNavigator navigator = getDoricContext().getDoricNavigator();
|
||||||
|
if (navigator != null) {
|
||||||
|
navigator.pop();
|
||||||
|
promise.resolve();
|
||||||
|
} else {
|
||||||
|
promise.reject(new JavaValue("Navigator not implemented"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@DoricMethod(thread = ThreadMode.UI)
|
||||||
|
public void popToRoot(DoricPromise promise) {
|
||||||
|
PackageManager pm = getDoricContext().getContext().getPackageManager();
|
||||||
|
Intent intent = pm.getLaunchIntentForPackage(getDoricContext().getContext().getPackageName());
|
||||||
|
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
||||||
|
getDoricContext().getContext().startActivity(intent);
|
||||||
|
promise.resolve();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { Panel, scroller, vlayout, text, layoutConfig, LayoutSpec, Color, gravity, Group, navigator, modal } from "doric";
|
import { Panel, scroller, vlayout, text, layoutConfig, LayoutSpec, Color, gravity, Group, navigator, modal, notification } from "doric";
|
||||||
import { colors, label } from "./utils";
|
import { colors, label } from "./utils";
|
||||||
@Entry
|
@Entry
|
||||||
class NaivgatorDemo extends Panel {
|
class NaivgatorDemo extends Panel {
|
||||||
@ -64,6 +64,46 @@ class NaivgatorDemo extends Panel {
|
|||||||
navigator(context).pop()
|
navigator(context).pop()
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
|
label('Register Pop Self').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
backgroundColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().just(),
|
||||||
|
onClick: () => {
|
||||||
|
notification(context).subscribe({
|
||||||
|
name: "PopSelf",
|
||||||
|
callback: () => {
|
||||||
|
navigator(context).popSelf()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
label('Send Pop Self').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
backgroundColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().just(),
|
||||||
|
onClick: () => {
|
||||||
|
notification(context).publish({
|
||||||
|
name: "PopSelf"
|
||||||
|
})
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
label('Back to Root').apply({
|
||||||
|
width: 200,
|
||||||
|
height: 50,
|
||||||
|
backgroundColor: colors[0],
|
||||||
|
textSize: 30,
|
||||||
|
textColor: Color.WHITE,
|
||||||
|
layoutConfig: layoutConfig().just(),
|
||||||
|
onClick: () => {
|
||||||
|
navigator(context).popToRoot()
|
||||||
|
},
|
||||||
|
}),
|
||||||
label('OpenURL').apply({
|
label('OpenURL').apply({
|
||||||
width: 200,
|
width: 200,
|
||||||
height: 50,
|
height: 50,
|
||||||
|
@ -26,6 +26,10 @@ extern NSString *const DORIC_MASK_RETRY;
|
|||||||
|
|
||||||
|
|
||||||
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
|
@interface DoricViewController : UIViewController <DoricNavigatorDelegate, DoricNavBarDelegate>
|
||||||
|
@property(nonatomic, copy) NSString *source;
|
||||||
|
@property(nonatomic, copy) NSString *alias;
|
||||||
|
@property(nonatomic, copy) NSString *extra;
|
||||||
|
|
||||||
@property(nonatomic, strong) DoricPanel *doricPanel;
|
@property(nonatomic, strong) DoricPanel *doricPanel;
|
||||||
@property(nonatomic) BOOL statusBarHidden;
|
@property(nonatomic) BOOL statusBarHidden;
|
||||||
@property(nonatomic) int statusBarMode;
|
@property(nonatomic) int statusBarMode;
|
||||||
|
@ -29,9 +29,6 @@ @interface DoricViewController ()
|
|||||||
@property(nonatomic) BOOL navBarHidden;
|
@property(nonatomic) BOOL navBarHidden;
|
||||||
@property(nonatomic, strong) UIImage *navBarImage;
|
@property(nonatomic, strong) UIImage *navBarImage;
|
||||||
@property(nonatomic, strong) UIView *maskView;
|
@property(nonatomic, strong) UIView *maskView;
|
||||||
@property(nonatomic, copy) NSString *source;
|
|
||||||
@property(nonatomic, copy) NSString *alias;
|
|
||||||
@property(nonatomic, copy) NSString *extra;
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation DoricViewController
|
@implementation DoricViewController
|
||||||
@ -105,9 +102,33 @@ - (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)doric_navigator_pop:(BOOL)animated {
|
- (void)doric_navigator_pop:(BOOL)animated {
|
||||||
|
if (self.presentingViewController) {
|
||||||
|
[self dismissViewControllerAnimated:animated completion:nil];
|
||||||
|
} else {
|
||||||
[self.navigationController popViewControllerAnimated:animated];
|
[self.navigationController popViewControllerAnimated:animated];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)doric_navigator_popSelf:(BOOL)animated {
|
||||||
|
if (self.presentingViewController) {
|
||||||
|
[self dismissViewControllerAnimated:animated completion:nil];
|
||||||
|
} else {
|
||||||
|
NSMutableArray *tempStack = [self.navigationController.viewControllers mutableCopy];
|
||||||
|
for (UIViewController *vc in self.navigationController.viewControllers) {
|
||||||
|
if (vc == self) {
|
||||||
|
[tempStack removeObject:vc];
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
[self.navigationController setViewControllers:[tempStack copy] animated:animated];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)doric_navigator_popToRoot:(BOOL)animated {
|
||||||
|
[self.navigationController popToRootViewControllerAnimated:animated];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
- (BOOL)doric_navBar_isHidden {
|
- (BOOL)doric_navBar_isHidden {
|
||||||
return self.navigationController.navigationBarHidden;
|
return self.navigationController.navigationBarHidden;
|
||||||
}
|
}
|
||||||
|
@ -23,4 +23,8 @@
|
|||||||
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra;
|
- (void)doric_navigator_push:(NSString *)source alias:(NSString *)alias animated:(BOOL)animated extra:(NSString *)extra;
|
||||||
|
|
||||||
- (void)doric_navigator_pop:(BOOL)animated;
|
- (void)doric_navigator_pop:(BOOL)animated;
|
||||||
|
|
||||||
|
- (void)doric_navigator_popSelf:(BOOL)animated;
|
||||||
|
|
||||||
|
- (void)doric_navigator_popToRoot:(BOOL)animated;
|
||||||
@end
|
@end
|
||||||
|
@ -22,7 +22,7 @@
|
|||||||
#import "DoricExtensions.h"
|
#import "DoricExtensions.h"
|
||||||
|
|
||||||
@implementation DoricNavigatorPlugin
|
@implementation DoricNavigatorPlugin
|
||||||
- (void)push:(NSDictionary *)params {
|
- (void)push:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
@ -35,15 +35,37 @@ - (void)push:(NSDictionary *)params {
|
|||||||
alias = [config optString:@"alias" defaultValue:source];
|
alias = [config optString:@"alias" defaultValue:source];
|
||||||
}
|
}
|
||||||
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
|
[self.doricContext.navigator doric_navigator_push:source alias:alias animated:animated extra:config[@"extra"]];
|
||||||
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)pop:(NSDictionary *)params {
|
- (void)pop:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
__weak typeof(self) _self = self;
|
__weak typeof(self) _self = self;
|
||||||
[self.doricContext dispatchToMainQueue:^{
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
__strong typeof(_self) self = _self;
|
__strong typeof(_self) self = _self;
|
||||||
BOOL animated = [params optBool:@"animated" defaultValue:YES];
|
BOOL animated = [params optBool:@"animated" defaultValue:YES];
|
||||||
[self.doricContext.navigator doric_navigator_pop:animated];
|
[self.doricContext.navigator doric_navigator_pop:animated];
|
||||||
|
[promise resolve:nil];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)popSelf:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
|
__weak typeof(self) _self = self;
|
||||||
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
|
__strong typeof(_self) self = _self;
|
||||||
|
BOOL animated = [params optBool:@"animated" defaultValue:YES];
|
||||||
|
[self.doricContext.navigator doric_navigator_popSelf:animated];
|
||||||
|
[promise resolve:nil];
|
||||||
|
}];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)popToRoot:(NSDictionary *)params withPromise:(DoricPromise *)promise {
|
||||||
|
__weak typeof(self) _self = self;
|
||||||
|
[self.doricContext dispatchToMainQueue:^{
|
||||||
|
__strong typeof(_self) self = _self;
|
||||||
|
BOOL animated = [params optBool:@"animated" defaultValue:YES];
|
||||||
|
[self.doricContext.navigator doric_navigator_popToRoot:animated];
|
||||||
|
[promise resolve:nil];
|
||||||
}];
|
}];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3120,6 +3120,14 @@ function navigator(context) {
|
|||||||
if (animated === void 0) { animated = true; }
|
if (animated === void 0) { animated = true; }
|
||||||
return context.callNative(moduleName, 'pop', { animated: animated });
|
return context.callNative(moduleName, 'pop', { animated: animated });
|
||||||
},
|
},
|
||||||
|
popSelf: function (animated) {
|
||||||
|
if (animated === void 0) { animated = true; }
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated: animated });
|
||||||
|
},
|
||||||
|
popToRoot: function (animated) {
|
||||||
|
if (animated === void 0) { animated = true; }
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated: animated });
|
||||||
|
},
|
||||||
openUrl: function (url) {
|
openUrl: function (url) {
|
||||||
return context.callNative(moduleName, "openUrl", url);
|
return context.callNative(moduleName, "openUrl", url);
|
||||||
},
|
},
|
||||||
|
@ -2419,6 +2419,12 @@ function navigator(context) {
|
|||||||
pop: (animated = true) => {
|
pop: (animated = true) => {
|
||||||
return context.callNative(moduleName, 'pop', { animated });
|
return context.callNative(moduleName, 'pop', { animated });
|
||||||
},
|
},
|
||||||
|
popSelf: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated });
|
||||||
|
},
|
||||||
|
popToRoot: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated });
|
||||||
|
},
|
||||||
openUrl: (url) => {
|
openUrl: (url) => {
|
||||||
return context.callNative(moduleName, "openUrl", url);
|
return context.callNative(moduleName, "openUrl", url);
|
||||||
},
|
},
|
||||||
|
@ -3940,6 +3940,12 @@ function navigator(context) {
|
|||||||
pop: (animated = true) => {
|
pop: (animated = true) => {
|
||||||
return context.callNative(moduleName, 'pop', { animated });
|
return context.callNative(moduleName, 'pop', { animated });
|
||||||
},
|
},
|
||||||
|
popSelf: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated });
|
||||||
|
},
|
||||||
|
popToRoot: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated });
|
||||||
|
},
|
||||||
openUrl: (url) => {
|
openUrl: (url) => {
|
||||||
return context.callNative(moduleName, "openUrl", url);
|
return context.callNative(moduleName, "openUrl", url);
|
||||||
},
|
},
|
||||||
|
2
doric-js/index.d.ts
vendored
2
doric-js/index.d.ts
vendored
@ -887,6 +887,8 @@ declare module 'doric/lib/src/native/navigator' {
|
|||||||
singlePage?: boolean | undefined;
|
singlePage?: boolean | undefined;
|
||||||
} | undefined) => Promise<any>;
|
} | undefined) => Promise<any>;
|
||||||
pop: (animated?: boolean) => Promise<any>;
|
pop: (animated?: boolean) => Promise<any>;
|
||||||
|
popSelf: (animated?: boolean) => Promise<any>;
|
||||||
|
popToRoot: (animated?: boolean) => Promise<any>;
|
||||||
openUrl: (url: string) => Promise<any>;
|
openUrl: (url: string) => Promise<any>;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
2
doric-js/lib/src/native/navigator.d.ts
vendored
2
doric-js/lib/src/native/navigator.d.ts
vendored
@ -10,5 +10,7 @@ export declare function navigator(context: BridgeContext): {
|
|||||||
singlePage?: boolean | undefined;
|
singlePage?: boolean | undefined;
|
||||||
} | undefined) => Promise<any>;
|
} | undefined) => Promise<any>;
|
||||||
pop: (animated?: boolean) => Promise<any>;
|
pop: (animated?: boolean) => Promise<any>;
|
||||||
|
popSelf: (animated?: boolean) => Promise<any>;
|
||||||
|
popToRoot: (animated?: boolean) => Promise<any>;
|
||||||
openUrl: (url: string) => Promise<any>;
|
openUrl: (url: string) => Promise<any>;
|
||||||
};
|
};
|
||||||
|
@ -18,6 +18,12 @@ export function navigator(context) {
|
|||||||
pop: (animated = true) => {
|
pop: (animated = true) => {
|
||||||
return context.callNative(moduleName, 'pop', { animated });
|
return context.callNative(moduleName, 'pop', { animated });
|
||||||
},
|
},
|
||||||
|
popSelf: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated });
|
||||||
|
},
|
||||||
|
popToRoot: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated });
|
||||||
|
},
|
||||||
openUrl: (url) => {
|
openUrl: (url) => {
|
||||||
return context.callNative(moduleName, "openUrl", url);
|
return context.callNative(moduleName, "openUrl", url);
|
||||||
},
|
},
|
||||||
|
@ -43,6 +43,12 @@ export function navigator(context: BridgeContext) {
|
|||||||
pop: (animated = true) => {
|
pop: (animated = true) => {
|
||||||
return context.callNative(moduleName, 'pop', { animated })
|
return context.callNative(moduleName, 'pop', { animated })
|
||||||
},
|
},
|
||||||
|
popSelf: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated })
|
||||||
|
},
|
||||||
|
popToRoot: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated })
|
||||||
|
},
|
||||||
openUrl: (url: string) => {
|
openUrl: (url: string) => {
|
||||||
return context.callNative(moduleName, "openUrl", url)
|
return context.callNative(moduleName, "openUrl", url)
|
||||||
},
|
},
|
||||||
|
6
doric-web/dist/index.js
vendored
6
doric-web/dist/index.js
vendored
@ -3994,6 +3994,12 @@ function navigator(context) {
|
|||||||
pop: (animated = true) => {
|
pop: (animated = true) => {
|
||||||
return context.callNative(moduleName, 'pop', { animated });
|
return context.callNative(moduleName, 'pop', { animated });
|
||||||
},
|
},
|
||||||
|
popSelf: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popSelf', { animated });
|
||||||
|
},
|
||||||
|
popToRoot: (animated = true) => {
|
||||||
|
return context.callNative(moduleName, 'popToRoot', { animated });
|
||||||
|
},
|
||||||
openUrl: (url) => {
|
openUrl: (url) => {
|
||||||
return context.callNative(moduleName, "openUrl", url);
|
return context.callNative(moduleName, "openUrl", url);
|
||||||
},
|
},
|
||||||
|
2
doric-web/dist/index.js.map
vendored
2
doric-web/dist/index.js.map
vendored
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user