foundation_fluttify/ios/Classes/platform_view/UIViewFactory.m

61 lines
1.4 KiB
Mathematica
Raw Permalink Normal View History

2024-11-17 16:01:34 +08:00
//
// 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 numberid
HEAP[[NSString stringWithFormat:@"%@", @(2147483647 - _viewId)]] = _view;
HEAP[[NSString stringWithFormat:@"%@:%@", @"UIView", @(_view.hash)]] = _view;
return _view;
}
@end