Flutter Engine
The Flutter Engine
Instance Methods | List of all members
FlutterPlatformViewController Class Reference

#import <FlutterPlatformViewController.h>

Inheritance diagram for FlutterPlatformViewController:

Instance Methods

(instancetype) - init [implementation]
 
(void) - onCreateWithViewIdentifier:viewType:arguments:result: [implementation]
 
(void) - onDisposeWithViewID:result: [implementation]
 
(void) - registerViewFactory:withId: [implementation]
 
(nullable NSView *) - platformViewWithID: [implementation]
 
(void) - handleMethodCall:result: [implementation]
 
(void) - handleAcceptGesture:result: [implementation]
 
(void) - handleRejectGesture:result: [implementation]
 
(void) - disposePlatformViews [implementation]
 

Detailed Description

Definition at line 17 of file FlutterPlatformViewController.h.

Method Documentation

◆ disposePlatformViews

- (void) disposePlatformViews
implementation

Removes platform views slated to be disposed via method handler calls.

Definition at line 17 of file FlutterPlatformViewController.mm.

158 {
159 if (_platformViewsToDispose.empty()) {
160 return;
161 }
162
163 FML_DCHECK([[NSThread currentThread] isMainThread])
164 << "Must be on the main thread to handle disposing platform views";
165 for (int64_t viewId : _platformViewsToDispose) {
166 NSView* view = _platformViews[viewId];
167 [view removeFromSuperview];
168 _platformViews.erase(viewId);
169 }
171}
std::map< int, NSView * > _platformViews
std::unordered_set< int64_t > _platformViewsToDispose
#define FML_DCHECK(condition)
Definition: logging.h:103

◆ handleAcceptGesture:result:

- (void) handleAcceptGesture: (FlutterMethodCall*)  call
result: (FlutterResult result 
implementation

Definition at line 17 of file FlutterPlatformViewController.mm.

129 NSDictionary<NSString*, id>* args = [call arguments];
130 NSAssert(args && args[@"id"], @"id argument is required");
131 int64_t viewId = [args[@"id"] longLongValue];
132 if (_platformViews.count(viewId) == 0) {
133 result([FlutterError errorWithCode:@"unknown_view"
134 message:@"trying to set gesture state for an unknown view"
135 details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
136 return;
137 }
138
139 // TODO(cbracken): Implement. https://github.com/flutter/flutter/issues/124492
140 result(nil);
141}
void(^ FlutterResult)(id _Nullable result)
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
GAsyncResult * result
Win32Message message
def call(args)
Definition: dom.py:159

◆ handleMethodCall:result:

- (void) handleMethodCall: (nonnull FlutterMethodCall *)  call
result: (nonnull FlutterResult result 
implementation

Handles platform view related method calls, for example create, dispose, etc.

Definition at line 17 of file FlutterPlatformViewController.mm.

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])];
96
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) {
102 FlutterStandardTypedData* creationArgsData = args[@"params"];
103 creationArgs = [codec decode:creationArgsData.data];
104 }
105 }
106 [self onCreateWithViewIdentifier:viewId
107 viewType:viewType
108 arguments:creationArgs
109 result:result];
110 } else {
111 result([FlutterError errorWithCode:@"unknown_view"
112 message:@"'id' argument must be passed to create a platform view."
113 details:[NSString stringWithFormat:@"'id' not specified."]]);
114 }
115 } else if ([[call method] isEqualToString:@"dispose"]) {
116 NSNumber* arg = [call arguments];
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];
123 } else {
125 }
126}
FLUTTER_DARWIN_EXPORT NSObject const * FlutterMethodNotImplemented

◆ handleRejectGesture:result:

- (void) handleRejectGesture: (FlutterMethodCall*)  call
result: (FlutterResult result 
implementation

Definition at line 17 of file FlutterPlatformViewController.mm.

144 NSDictionary<NSString*, id>* args = [call arguments];
145 NSAssert(args && args[@"id"], @"id argument is required");
146 int64_t viewId = [args[@"id"] longLongValue];
147 if (_platformViews.count(viewId) == 0) {
148 result([FlutterError errorWithCode:@"unknown_view"
149 message:@"trying to set gesture state for an unknown view"
150 details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
151 return;
152 }
153
154 // TODO(cbracken): Implement. https://github.com/flutter/flutter/issues/124492
155 result(nil);
156}

◆ init

- (instancetype) init
implementation

Definition at line 17 of file FlutterPlatformViewController.mm.

20 {
21 self = [super init];
22 if (self) {
23 _platformViewFactories = [[NSMutableDictionary alloc] init];
24 }
25 return self;
26}

◆ onCreateWithViewIdentifier:viewType:arguments:result:

- (void) onCreateWithViewIdentifier: (int64_t)  viewId
viewType: (nonnull NSString *)  viewType
arguments: (nullable id args
result: (nonnull FlutterResult result 
implementation

Creates a platform view of viewType with viewId and arguments passed from the framework's creationParams constructor parameter. FlutterResult is updated to contain nil for success or to contain a FlutterError if there is an error.

Definition at line 17 of file FlutterPlatformViewController.mm.

28 :(int64_t)viewId
29 viewType:(nonnull NSString*)viewType
30 arguments:(nullable id)args
31 result:(nonnull FlutterResult)result {
32 if (_platformViews.count(viewId) != 0) {
33 result([FlutterError errorWithCode:@"recreating_view"
34 message:@"trying to create an already created view"
35 details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
36 return;
37 }
38
39 NSObject<FlutterPlatformViewFactory>* factory = _platformViewFactories[viewType];
40 if (!factory) {
42 errorWithCode:@"unregistered_view_type"
43 message:[NSString stringWithFormat:@"A UIKitView widget is trying to create a "
44 @"PlatformView with an unregistered type: < %@ >",
45 viewType]
46 details:@"If you are the author of the PlatformView, make sure `registerViewFactory` "
47 @"is invoked.\n"
48 @"See: "
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`."]);
53 return;
54 }
55
56 NSView* platform_view = [factory createWithViewIdentifier:viewId arguments:args];
57 // Flutter compositing requires CALayer-backed platform views.
58 // Force the platform view to be backed by a CALayer.
59 [platform_view setWantsLayer:YES];
61 result(nil);
62}
std::unique_ptr< flutter::PlatformViewIOS > platform_view
const uintptr_t id

◆ onDisposeWithViewID:result:

- (void) onDisposeWithViewID: (int64_t)  viewId
result: (nonnull FlutterResult result 
implementation

Disposes the platform view with viewId. FlutterResult is updated to contain nil for success or a FlutterError if there is an error.

Definition at line 17 of file FlutterPlatformViewController.mm.

64 :(int64_t)viewId result:(nonnull FlutterResult)result {
65 if (_platformViews.count(viewId) == 0) {
66 result([FlutterError errorWithCode:@"unknown_view"
67 message:@"trying to dispose an unknown"
68 details:[NSString stringWithFormat:@"view id: '%lld'", viewId]]);
69 return;
70 }
71
72 // The following disposePlatformViews call will dispose the views.
73 _platformViewsToDispose.insert(viewId);
74 result(nil);
75}

◆ platformViewWithID:

- (nullable NSView *) platformViewWithID: (int64_t)  viewId
implementation

Returns the platform view associated with the viewId.

Definition at line 17 of file FlutterPlatformViewController.mm.

82 :(int64_t)viewId {
83 if (_platformViews.count(viewId)) {
84 return _platformViews[viewId];
85 } else {
86 return nil;
87 }
88}

◆ registerViewFactory:withId:

- (void) registerViewFactory: (nonnull NSObject< FlutterPlatformViewFactory > *)  factory
withId: (nonnull NSString *)  factoryId 
implementation

Register a view factory by adding an entry into the platformViewFactories map with key factoryId and value factory.

Definition at line 17 of file FlutterPlatformViewController.mm.

77 :(nonnull NSObject<FlutterPlatformViewFactory>*)factory
78 withId:(nonnull NSString*)factoryId {
79 _platformViewFactories[factoryId] = factory;
80}

The documentation for this class was generated from the following files: