1
This commit is contained in:
29
ios/Classes/platform_view/UIViewFactory.h
Normal file
29
ios/Classes/platform_view/UIViewFactory.h
Normal file
@ -0,0 +1,29 @@
|
||||
//
|
||||
// UIViewFactory.h
|
||||
// foundation_fluttify
|
||||
//
|
||||
// Created by Yohom Bao on 2020/4/17.
|
||||
//
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
#import <Flutter/Flutter.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@interface UIViewFactory : NSObject <FlutterPlatformViewFactory>
|
||||
|
||||
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar;
|
||||
|
||||
@property(nonatomic) NSObject<FlutterPluginRegistrar>* registrar;
|
||||
|
||||
@end
|
||||
|
||||
@interface UIViewPlatformView : NSObject <FlutterPlatformView>
|
||||
|
||||
- (instancetype)initWithViewId:(int64_t)viewId frame:(CGRect)frame registrar:(NSObject <FlutterPluginRegistrar> *)registrar;
|
||||
|
||||
@property(nonatomic) NSObject<FlutterPluginRegistrar>* registrar;
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
60
ios/Classes/platform_view/UIViewFactory.m
Normal file
60
ios/Classes/platform_view/UIViewFactory.m
Normal file
@ -0,0 +1,60 @@
|
||||
//
|
||||
// UIViewFactory.m
|
||||
// foundation_fluttify
|
||||
//
|
||||
// Created by Yohom Bao on 2020/4/17.
|
||||
//
|
||||
|
||||
#import "UIViewFactory.h"
|
||||
#import "FoundationFluttifyPlugin.h"
|
||||
|
||||
// Dart端随机存取对象的容器
|
||||
extern NSMutableDictionary<NSString *, NSObject *> *HEAP;
|
||||
|
||||
@implementation UIViewFactory {
|
||||
}
|
||||
|
||||
- (instancetype)initWithRegistrar:(NSObject <FlutterPluginRegistrar> *)registrar {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_registrar = registrar;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSObject <FlutterPlatformView> *)createWithFrame:(CGRect)frame viewIdentifier:(int64_t)viewId arguments:(id _Nullable)args {
|
||||
return [[UIViewPlatformView alloc] initWithViewId:viewId frame: frame registrar:_registrar];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation UIViewPlatformView {
|
||||
int64_t _viewId;
|
||||
CGRect _frame;
|
||||
UIView* _view;
|
||||
}
|
||||
|
||||
- (instancetype)initWithViewId:(int64_t)viewId frame:(CGRect)frame registrar:(NSObject <FlutterPluginRegistrar> *)registrar {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
_viewId = viewId;
|
||||
_registrar = registrar;
|
||||
_frame = frame;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (UIView *)view {
|
||||
if (_view == nil) {
|
||||
_view = [[UIView alloc] initWithFrame:_frame];
|
||||
}
|
||||
// 这里用一个magic number调整一下id
|
||||
HEAP[[NSString stringWithFormat:@"%@", @(2147483647 - _viewId)]] = _view;
|
||||
HEAP[[NSString stringWithFormat:@"%@:%@", @"UIView", @(_view.hash)]] = _view;
|
||||
return _view;
|
||||
}
|
||||
|
||||
@end
|
||||
|
Reference in New Issue
Block a user