Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Conversation

@amirh
Copy link
Contributor

@amirh amirh commented Oct 17, 2018

Note that this is my first time writing ObjC, don't assume I know what I'm doing 😄, feedback is welcomed.

  • Adds a FlutterPlatformViewFactory protocol - a simple factory protocol to be implemented by plugins
    that exposes a UIView for embeeding in Flutter apps.
  • Adds a FlutterPlatformView protocol, which is used to associate a
    dispose callback with a UIView created by a FlutterPlatformViewFactory.
  • Exposes a registerViewFactory method in FlutterPluginRegistrar.
  • Implements the flutter/platform_views system channel on iOS, allowing
    Dart code to ask for creation/destruction of UIViews.

flutter/flutter#19030

@amirh amirh requested a review from chinmaygarde October 17, 2018 17:04
@amirh amirh force-pushed the platform_views_controller branch from 335e125 to 1dc1968 Compare October 17, 2018 17:06
@amirh
Copy link
Contributor Author

amirh commented Oct 17, 2018

cc @cbracken @dnfield

#include "flutter/fml/platform/darwin/scoped_nsobject.h"
#include "flutter/shell/platform/darwin/ios/framework/Headers/FlutterChannels.h"

@implementation FlutterPlatformViewsController {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How is this meant to be different from a FlutterViewController?

I also wonder if we're further confusing some already confusing naming conventions. We have

  • FlutterViewController, which is a UIViewController
  • FlutterView which is a UIView
  • PlatformViewIOS, which is a shell::PlatformView (but not a view in the sense of a UIView or UIViewController

It might be better if we could extend FlutterViewController to do the job that this class is doing now, especially with some of the refactoring I've been working on to disentangle the engine from the view controller.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I agree the name is confusing as this is not a ViewController but the controller for the platform views... lets see if we can come up with a better name (let me know if you have a good suggestion).

As for keeping this logic inside FlutterViewController vs keeping it in a separate class, we can definitely do both, I actually discussed this with Chinmay and we didn't have a really strong preference, we leaned to encapsulating it in it's own file as FlutterViewController is starting to get a little big (at least before the coming refactor).
Keeping it out of FlutterViewController might also make this specific part of the logic a little easier to unit test (the only dependency a test needs to provide is a messenger in order to exercise the platform views code).

@amirh amirh force-pushed the platform_views_controller branch 2 times, most recently from 7228ff0 to c2f0487 Compare October 17, 2018 18:26
NS_ASSUME_NONNULL_BEGIN

/**
An instance of a `UIView` created by a `FlutterPlatformViewFactory`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've reformatted the documentation in #6447 - the format being used previously was inconsistent and didn't play with the doc generator very well. This one should have * all the way down each line.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done.
Do you know if there's a way to configure Xcode to play well with these leading * ?

@protocol FlutterPlatformView <NSObject>
- (UIView*)view;
/**
Called when the Flutter engine no longer needs this `view`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

The implementation of this method should create a new `UIView` and return a `FlutterPlatformView`
that wraps it.

- Parameters:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(@param can be used multiple times, and will format as a table)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#ifndef FLUTTER_FLUTTERPLATFORMVIEWS_H_
#define FLUTTER_FLUTTERPLATFORMVIEWS_H_

#import <CoreMedia/CoreMedia.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary header import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* This protocol is used to associate a view with a dispose callback.
*/
FLUTTER_EXPORT
@protocol FlutterPlatformView <NSObject>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's get rid of this protocol entirely and make the create call return a view.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* code, this will be null. Otherwise this will be the value sent from the Dart code as decoded by
* `createArgsCodec`.
*/
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Objective-C method names usually don't have conjunctions. Also, don't shorten arguments to args. See NSInvocation for prior art on this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment for Id and Identifier here and elsewhere.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#define FLUTTER_FLUTTERPLATFORMVIEWS_H_

#import <CoreMedia/CoreMedia.h>
#import <Foundation/Foundation.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Foundation is implied by UIKit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#import <UIKit/UIKit.h>

#include "FlutterCodecs.h"
#include "FlutterMacros.h"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Always #import Objective-C header. Though we usually add explicit guards to all our headers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private:
fml::scoped_nsobject<FlutterMethodChannel> channel_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<long long, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please replace this with one of the types in stdint.h

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Contributor Author

@amirh amirh left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the review! PTAL.

#ifndef FLUTTER_FLUTTERPLATFORMVIEWS_H_
#define FLUTTER_FLUTTERPLATFORMVIEWS_H_

#import <CoreMedia/CoreMedia.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#define FLUTTER_FLUTTERPLATFORMVIEWS_H_

#import <CoreMedia/CoreMedia.h>
#import <Foundation/Foundation.h>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

#import <UIKit/UIKit.h>

#include "FlutterCodecs.h"
#include "FlutterMacros.h"
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* This protocol is used to associate a view with a dispose callback.
*/
FLUTTER_EXPORT
@protocol FlutterPlatformView <NSObject>
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* code, this will be null. Otherwise this will be the value sent from the Dart code as decoded by
* `createArgsCodec`.
*/
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private:
fml::scoped_nsobject<FlutterMethodChannel> channel_;
std::map<std::string, fml::scoped_nsobject<NSObject<FlutterPlatformViewFactory>>> factories_;
std::map<long long, fml::scoped_nsobject<NSObject<FlutterPlatformView>>> views_;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

amirh added 4 commits October 23, 2018 14:48
* Adds a FlutterPlatformViewFactory protocol - a simple factory protocol to be implemented by plugins
  that exposes a UIView for embeeding in Flutter apps.
* Adds a FlutterPlatformView protocol, which is used to associate a
  dispose callback with a `UIView` created by a FlutterPlatformViewFactory.
* Exposes a registerViewFactory method in FlutterPluginRegistrar.
* Implements the `flutter/platform_views` system channel on iOS, allowing
  Dart code to ask for creation/destruction of UIViews.
@amirh amirh force-pushed the platform_views_controller branch from efccad2 to f62c939 Compare October 23, 2018 21:49
Copy link
Contributor

@chinmaygarde chinmaygarde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit but lgtm otherwise. Thanks!

void OnMethodCall(FlutterMethodCall* call, FlutterResult& result);
void OnCreate(FlutterMethodCall* call, FlutterResult& result);
void OnDispose(FlutterMethodCall* call, FlutterResult& result);
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Disallow copy and assign here. See the section about this in the style guide https://google.github.io/styleguide/cppguide.html#Copyable_Movable_Types.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@amirh amirh merged commit 9669b70 into flutter:master Oct 24, 2018
@amirh amirh deleted the platform_views_controller branch October 24, 2018 22:07
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 25, 2018
flutter/engine@2586e94...9f2e2ba

git log 2586e94..9f2e2ba --no-merges --oneline
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 25, 2018
flutter/engine@2586e94...914551b

git log 2586e94..914551b --no-merges --oneline
914551b Dart SDK roll for 2018-10-24
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 25, 2018
flutter/engine@2586e94...ff0525f

git log 2586e94..ff0525f --no-merges --oneline
ff0525f Add missing entry-points. (flutter/engine#6634)
08771fe Revert dart before engine commit 26e8840 (flutter/engine#6656)
914551b Dart SDK roll for 2018-10-24
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to engine-flutter-autoroll/flutter that referenced this pull request Oct 25, 2018
flutter/engine@2586e94...a6e816b

git log 2586e94..a6e816b --no-merges --oneline
a6e816b Roll src/third_party/skia 4f598e8c829a..dfca8f6adb6b (7 commits) (flutter/engine#6658)
ff0525f Add missing entry-points. (flutter/engine#6634)
08771fe Revert dart before engine commit 26e8840 (flutter/engine#6656)
914551b Dart SDK roll for 2018-10-24
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)

The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
engine-flutter-autoroll added a commit to flutter/flutter that referenced this pull request Oct 25, 2018
flutter/engine@2586e94...a6e816b

git log 2586e94..a6e816b --no-merges --oneline
a6e816b Roll src/third_party/skia 4f598e8c829a..dfca8f6adb6b (7 commits) (flutter/engine#6658)
ff0525f Add missing entry-points. (flutter/engine#6634)
08771fe Revert dart before engine commit 26e8840 (flutter/engine#6656)
914551b Dart SDK roll for 2018-10-24
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)


The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&#39;d on the roll, and stop the roller if necessary.
Xavjer pushed a commit to Xavjer/flutter that referenced this pull request Nov 1, 2018
flutter/engine@2586e94...a6e816b

git log 2586e94..a6e816b --no-merges --oneline
a6e816b Roll src/third_party/skia 4f598e8c829a..dfca8f6adb6b (7 commits) (flutter/engine#6658)
ff0525f Add missing entry-points. (flutter/engine#6634)
08771fe Revert dart before engine commit 26e8840 (flutter/engine#6656)
914551b Dart SDK roll for 2018-10-24
9f2e2ba Add/expose API for Paragraph.getBoxesForRange BoxHeightStyle and BoxWidthStyle. (flutter/engine#6644)
9669b70 Add an iOS PlatformViewsController for creating/disposing UIViews. (flutter/engine#6569)
6c2477b fix setter for viewOpaque (flutter/engine#6653)
2bd8c94 Roll src/third_party/skia a7682c8c73e4..4f598e8c829a (8 commits) (flutter/engine#6654)
e1e6093 Realize kernel asset mappings on a worker thread if one is available. (flutter/engine#6648)
d3874a9 Roll src/third_party/skia 3b57279fd65a..a7682c8c73e4 (9 commits) (flutter/engine#6652)
3dddf4d Roll src/third_party/skia 8429c7930291..3b57279fd65a (2 commits) (flutter/engine#6650)
7b3bb62 Roll src/third_party/skia 3aca39df7b22..8429c7930291 (5 commits) (flutter/engine#6647)
26e8840 Dart SDK roll for 2018-10-23
9829c51 Roll src/third_party/skia b46c4d0925ad..3aca39df7b22 (12 commits) (flutter/engine#6643)


The AutoRoll server is located here: https://autoroll.skia.org/r/flutter-engine-flutter-autoroll

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/&#43;/master/autoroll/README.md

If the roll is causing failures, please contact the current sheriff, who should
be CC&flutter#39;d on the roll, and stop the roller if necessary.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants