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];
97 NSString* viewType = args[@"viewType"];
98 if (![viewType isKindOfClass:[NSString
class]]) {
100 errorWithCode:
@"unknown_view"
101 message:
@"'viewType' argument must be a string to create a platform view."
106 id creationArgs = nil;
107 NSObject<FlutterPlatformViewFactory>* factory = _platformViewFactories[viewType];
108 if ([factory respondsToSelector:
@selector(createArgsCodec)]) {
109 NSObject<FlutterMessageCodec>* codec = [factory createArgsCodec];
110 if (codec != nil && args[
@"params"] != nil) {
112 creationArgs = [codec decode:creationArgsData.data];
115 [
self onCreateWithViewIdentifier:viewId
117 arguments:creationArgs
121 message:
@"'id' argument must be passed to create a platform view."
122 details:[NSString stringWithFormat:
@"'id' not specified."]]);
124 }
else if ([[call method] isEqualToString:
@"dispose"]) {
126 int64_t viewId = [arg longLongValue];
127 [
self onDisposeWithViewID:viewId result:result];
128 }
else if ([[call method] isEqualToString:
@"acceptGesture"]) {
129 [
self handleAcceptGesture:call result:result];
130 }
else if ([[call method] isEqualToString:
@"rejectGesture"]) {
131 [
self handleRejectGesture:call result:result];
138 NSDictionary<NSString*, id>* args = [call
arguments];
139 NSAssert(args && args[
@"id"],
@"id argument is required");
140 int64_t viewId = [args[@"id"] longLongValue];
143 message:
@"trying to set gesture state for an unknown view"
144 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
153 NSDictionary<NSString*, id>* args = [call
arguments];
154 NSAssert(args && args[
@"id"],
@"id argument is required");
155 int64_t viewId = [args[@"id"] longLongValue];
158 message:
@"trying to set gesture state for an unknown view"
159 details:[NSString stringWithFormat:
@"view id: '%lld'", viewId]]);
167 - (void)disposePlatformViews {
172 FML_DCHECK([[NSThread currentThread] isMainThread])
173 <<
"Must be on the main thread to handle disposing platform views";
176 [view removeFromSuperview];
186 [
self disposePlatformViews];
void(^ FlutterResult)(id _Nullable result)
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented