Merge branch 'feature/slider' into 'master'
Feature/slider See merge request !26
This commit is contained in:
commit
f585c72407
@ -15,11 +15,15 @@
|
||||
*/
|
||||
package pub.doric.shader;
|
||||
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.graphics.drawable.BitmapDrawable;
|
||||
import android.graphics.drawable.Drawable;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import android.text.TextUtils;
|
||||
import android.util.Base64;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@ -34,6 +38,9 @@ import pub.doric.extension.bridge.DoricPlugin;
|
||||
import com.github.pengfeizhou.jscore.JSONBuilder;
|
||||
import com.github.pengfeizhou.jscore.JSValue;
|
||||
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
/**
|
||||
* @Description: com.github.penfeizhou.doric.widget
|
||||
* @Author: pengfei.zhou
|
||||
@ -96,6 +103,23 @@ public class ImageNode extends ViewNode<ImageView> {
|
||||
case "loadCallback":
|
||||
this.loadCallbackId = prop.asString().value();
|
||||
break;
|
||||
case "imageBase64":
|
||||
Pattern r = Pattern.compile("data:image/(\\S+?);base64,(\\S+)");
|
||||
Matcher m = r.matcher(prop.asString().value());
|
||||
if (m.find()) {
|
||||
String imageType = m.group(1);
|
||||
String base64 = m.group(2);
|
||||
if (!TextUtils.isEmpty(imageType) && !TextUtils.isEmpty(base64)) {
|
||||
try {
|
||||
byte[] data = Base64.decode(base64, Base64.DEFAULT);
|
||||
Bitmap bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
|
||||
view.setImageBitmap(bitmap);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
super.blend(view, name, prop);
|
||||
break;
|
||||
|
File diff suppressed because one or more lines are too long
@ -23,4 +23,5 @@
|
||||
#import "DoricPanel.h"
|
||||
#import "DoricJSLoaderManager.h"
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
#import "DoricViewController.h"
|
||||
#import "DoricViewController.h"
|
||||
#import "DoricDefaultNavigator.h"
|
@ -29,7 +29,7 @@ NS_ASSUME_NONNULL_BEGIN
|
||||
@class DoricRootNode;
|
||||
|
||||
@interface DoricContext : NSObject
|
||||
@property(nonatomic, weak) id <DoricNavigatorProtocol> navigator;
|
||||
@property(nonatomic, strong) id <DoricNavigatorProtocol> navigator;
|
||||
@property(nonatomic, strong) NSString *contextId;
|
||||
@property(nonatomic, strong) DoricDriver *driver;
|
||||
@property(nonatomic, strong) NSMutableDictionary *pluginInstanceMap;
|
||||
|
@ -24,9 +24,7 @@ @implementation DoricPanel
|
||||
|
||||
- (void)config:(NSString *)script alias:(NSString *)alias {
|
||||
self.doricContext = [[[DoricContext alloc] initWithScript:script source:alias] also:^(DoricContext *it) {
|
||||
if ([self.parentViewController conformsToProtocol:@protocol(DoricNavigatorProtocol)]) {
|
||||
it.navigator = (id <DoricNavigatorProtocol>) self.parentViewController;
|
||||
}
|
||||
it.navigator = [[DoricDefaultNavigator alloc] initWithNavigationController:self.navigationController];
|
||||
[it.rootNode setupRootView:[[DoricStackView new] also:^(DoricStackView *it) {
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height;
|
||||
|
@ -20,6 +20,6 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
|
||||
@interface DoricViewController : UIViewController <DoricNavigatorProtocol>
|
||||
@interface DoricViewController : UIViewController
|
||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias;
|
||||
@end
|
@ -27,45 +27,23 @@
|
||||
@implementation DoricViewController
|
||||
- (instancetype)initWithScheme:(NSString *)scheme alias:(NSString *)alias {
|
||||
if (self = [super init]) {
|
||||
[self push:scheme alias:alias];
|
||||
self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"返回"
|
||||
style:UIBarButtonItemStylePlain
|
||||
target:self
|
||||
action:@selector(pop)];
|
||||
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
||||
result.resultCallback = ^(NSString *result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
DoricPanel *panel = [DoricPanel new];
|
||||
[panel.view also:^(UIView *it) {
|
||||
it.backgroundColor = [UIColor whiteColor];
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height - 88;
|
||||
it.top = 88;
|
||||
}];
|
||||
[self.view addSubview:panel.view];
|
||||
[self addChildViewController:panel];
|
||||
[panel config:result alias:alias];
|
||||
|
||||
});
|
||||
};
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)push:(NSString *)scheme alias:(NSString *)alias {
|
||||
DoricAsyncResult <NSString *> *result = [DoricJSLoaderManager.instance request:scheme];
|
||||
result.resultCallback = ^(NSString *result) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
DoricPanel *panel = [DoricPanel new];
|
||||
[panel.view also:^(UIView *it) {
|
||||
it.backgroundColor = [UIColor whiteColor];
|
||||
it.width = self.view.width;
|
||||
it.height = self.view.height - 88;
|
||||
it.top = 88;
|
||||
}];
|
||||
[self.view addSubview:panel.view];
|
||||
[self addChildViewController:panel];
|
||||
[panel config:result alias:alias];
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
- (void)pop {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
if (self.childViewControllers.count > 1) {
|
||||
[self.childViewControllers.lastObject also:^(UIViewController *it) {
|
||||
[it removeFromParentViewController];
|
||||
[it.view removeFromSuperview];
|
||||
}];
|
||||
} else {
|
||||
[self.navigationController popViewControllerAnimated:NO];
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@end
|
||||
|
10
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h
Normal file
10
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.h
Normal file
@ -0,0 +1,10 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/25.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import "DoricNavigatorProtocol.h"
|
||||
|
||||
@interface DoricDefaultNavigator : NSObject <DoricNavigatorProtocol>
|
||||
- (instancetype)initWithNavigationController:(UINavigationController *)navigationController;
|
||||
@end
|
29
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m
Normal file
29
iOS/Pod/Classes/Navigator/DoricDefaultNavigator.m
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Created by pengfei.zhou on 2019/11/25.
|
||||
//
|
||||
|
||||
#import "DoricDefaultNavigator.h"
|
||||
#import "DoricViewController.h"
|
||||
|
||||
@interface DoricDefaultNavigator ()
|
||||
@property(nonatomic, weak) UINavigationController *navigationController;
|
||||
@end
|
||||
|
||||
@implementation DoricDefaultNavigator
|
||||
- (instancetype)initWithNavigationController:(UINavigationController *)navigationController {
|
||||
if (self = [super init]) {
|
||||
_navigationController = navigationController;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated {
|
||||
DoricViewController *viewController = [[DoricViewController alloc] initWithScheme:scheme alias:alias];
|
||||
[self.navigationController pushViewController:viewController animated:animated];
|
||||
}
|
||||
|
||||
- (void)pop:(BOOL)animated {
|
||||
[self.navigationController popViewControllerAnimated:animated];
|
||||
}
|
||||
|
||||
@end
|
@ -5,7 +5,7 @@
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
@protocol DoricNavigatorProtocol <NSObject>
|
||||
- (void)push:(NSString *)scheme alias:(NSString *)alias;
|
||||
- (void)push:(NSString *)scheme alias:(NSString *)alias animated:(BOOL)animated;
|
||||
|
||||
- (void)pop;
|
||||
- (void)pop:(BOOL)animated;
|
||||
@end
|
@ -22,10 +22,22 @@
|
||||
|
||||
@implementation DoricNavigatorPlugin
|
||||
- (void)push:(NSDictionary *)params {
|
||||
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"]];
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL animated = YES;
|
||||
if (params[@"animated"]) {
|
||||
animated = [params[@"animated"] boolValue];
|
||||
}
|
||||
[self.doricContext.navigator push:params[@"scheme"] alias:params[@"alias"] animated:animated];
|
||||
});
|
||||
}
|
||||
|
||||
- (void)pop {
|
||||
[self.doricContext.navigator pop];
|
||||
- (void)pop:(NSDictionary *)params {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
BOOL animated = YES;
|
||||
if (params[@"animated"]) {
|
||||
animated = [params[@"animated"] boolValue];
|
||||
}
|
||||
[self.doricContext.navigator pop:animated];
|
||||
});
|
||||
}
|
||||
@end
|
@ -72,6 +72,15 @@ - (void)blendView:(UIImageView *)view forPropName:(NSString *)name propValue:(id
|
||||
}
|
||||
} else if ([@"loadCallback" isEqualToString:name]) {
|
||||
self.loadCallbackId = prop;
|
||||
} else if ([@"imageBase64" isEqualToString:name]) {
|
||||
NSString *base64 = prop;
|
||||
if (YES == [base64 hasPrefix:@"data:image"]) {
|
||||
base64 = [base64 componentsSeparatedByString:@","].lastObject;
|
||||
}
|
||||
NSData *imageData = [[NSData alloc] initWithBase64EncodedString:base64
|
||||
options:NSDataBase64DecodingIgnoreUnknownCharacters];
|
||||
UIImage *image = [UIImage imageWithData:imageData];
|
||||
self.view.image = image;
|
||||
} else {
|
||||
[super blendView:view forPropName:name propValue:prop];
|
||||
}
|
||||
|
@ -50,6 +50,7 @@ export enum ScaleType {
|
||||
|
||||
export interface IImage extends IView {
|
||||
imageUrl?: string
|
||||
imageBase64?: string
|
||||
scaleType?: ScaleType
|
||||
loadCallback?: (image: { width: number; height: number } | undefined) => void
|
||||
}
|
||||
@ -57,7 +58,8 @@ export interface IImage extends IView {
|
||||
export class Image extends View implements IImage {
|
||||
@Property
|
||||
imageUrl?: string
|
||||
|
||||
@Property
|
||||
imageBase64?: string
|
||||
@Property
|
||||
scaleType?: ScaleType
|
||||
|
||||
|
@ -170,13 +170,13 @@ export function storage(context: BridgeContext) {
|
||||
|
||||
export function navigator(context: BridgeContext) {
|
||||
return {
|
||||
push: (scheme: string, alias: string) => {
|
||||
push: (scheme: string, alias: string, animated = true) => {
|
||||
return context.navigator.push({
|
||||
scheme, alias
|
||||
scheme, alias, animated
|
||||
})
|
||||
},
|
||||
pop: () => {
|
||||
return context.navigator.pop()
|
||||
pop: (animated = true) => {
|
||||
return context.navigator.pop({ animated })
|
||||
},
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user