5 #include "flutter/fml/logging.h"
11 NSMutableDictionary<NSString*, NSObject<FlutterPlatformViewFactory>*>* _platformViewFactories;
20 - (instancetype)init {
23 _platformViewFactories = [[NSMutableDictionary alloc] init];
28 - (void)onCreateWithViewIdentifier:(int64_t)viewId
29 viewType:(nonnull NSString*)viewType
30 arguments:(nullable
id)args
34 message:
@"trying to create an already created view"
35 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
39 NSObject<FlutterPlatformViewFactory>* factory = _platformViewFactories[viewType];
42 errorWithCode:
@"unregistered_view_type"
43 message:[NSString stringWithFormat:
@"A UIKitView widget is trying to create a "
44 @"PlatformView with an unregistered type: < %@ >",
46 details:
@"If you are the author of the PlatformView, make sure `registerViewFactory` "
49 @"https://docs.flutter.dev/development/platform-integration/"
50 @"platform-views#on-the-platform-side-1 for more details.\n"
51 @"If you are not the author of the PlatformView, make sure to call "
52 @"`GeneratedPluginRegistrant.register`."]);
56 NSView* platform_view = [factory createWithViewIdentifier:viewId arguments:args];
59 [platform_view setWantsLayer:YES];
64 - (void)onDisposeWithViewID:(int64_t)viewId result:(nonnull
FlutterResult)result {
67 message:
@"trying to dispose an unknown"
68 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
78 withId:(nonnull NSString*)factoryId {
79 _platformViewFactories[factoryId] = factory;
82 - (nullable NSView*)platformViewWithID:(int64_t)viewId {
91 if ([[call method] isEqualToString:
@"create"]) {
92 NSMutableDictionary<NSString*, id>* args = [call
arguments];
93 if ([args objectForKey:
@"id"]) {
94 int64_t viewId = [args[@"id"] longLongValue];
95 NSString* viewType = [NSString stringWithUTF8String:([args[@"viewType"] UTF8String])];
97 id creationArgs = nil;
98 NSObject<FlutterPlatformViewFactory>* factory = _platformViewFactories[viewType];
99 if ([factory respondsToSelector:
@selector(createArgsCodec)]) {
100 NSObject<FlutterMessageCodec>* codec = [factory createArgsCodec];
101 if (codec != nil && args[
@"params"] != nil) {
103 creationArgs = [codec decode:creationArgsData.data];
106 [
self onCreateWithViewIdentifier:viewId
108 arguments:creationArgs
112 message:
@"'id' argument must be passed to create a platform view."
113 details:[NSString stringWithFormat:
@"'id' not specified."]]);
115 }
else if ([[call method] isEqualToString:
@"dispose"]) {
117 int64_t viewId = [arg longLongValue];
118 [
self onDisposeWithViewID:viewId result:result];
119 }
else if ([[call method] isEqualToString:
@"acceptGesture"]) {
120 [
self handleAcceptGesture:call result:result];
121 }
else if ([[call method] isEqualToString:
@"rejectGesture"]) {
122 [
self handleRejectGesture:call result:result];
129 NSDictionary<NSString*, id>* args = [call
arguments];
130 NSAssert(args && args[
@"id"],
@"id argument is required");
131 int64_t viewId = [args[@"id"] longLongValue];
134 message:
@"trying to set gesture state for an unknown view"
135 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
144 NSDictionary<NSString*, id>* args = [call
arguments];
145 NSAssert(args && args[
@"id"],
@"id argument is required");
146 int64_t viewId = [args[@"id"] longLongValue];
149 message:
@"trying to set gesture state for an unknown view"
150 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
158 - (void)disposePlatformViews {
163 FML_DCHECK([[NSThread currentThread] isMainThread])
164 <<
"Must be on the main thread to handle disposing platform views";
167 [view removeFromSuperview];