-
Notifications
You must be signed in to change notification settings - Fork 3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview #4523
Conversation
/// * Update `LiveDataHostApiImpl#getValue` is updated to properly return | ||
/// identifiers for instances of type S. | ||
/// * Update `ObserverFlutterApiWrapper#onChanged` to properly handle receiving | ||
/// calls with instances of type S if a LiveData<S> instance is observed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is unrelated. Pigeon must have carried over my comment I left in camerax_library.dart
in a previous PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, pigeon will just keep adding it back since it's part of the source file
...camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java
Outdated
Show resolved
Hide resolved
/// this fallback rule is used. | ||
/// | ||
/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_NONE(). | ||
static const int fallbackRuleNone = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not a blocker for this PR, but I did want to ask if it would be better for us to make a getter for these constants.
We are essentially relying on the camerax implementations to never change these values, and if they did it might not get caught by our testing because they could still be valid values, but just not actually correspond to what they are named. I know we are doing this in existing camerax and webview wrappings though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My initial thought is that changing them to getters wouldn't be a significant improvement. If the values change, we likely will be quick to find out. Plus, there's the risk that they change the name and a getter would fail there. Not sure which case is more likely but I think it's something to consider. @bparrishMines any thoughts on this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's hard to change them to getters since it would require an async call. Which would make it unintuitive to use. You could also add a Java unit test that verifies that these constants stay the same. However, this would still be susceptible to an instance where the constant values are different for different Android versions. Although this case is probably extremely rare.
packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart
Outdated
Show resolved
Hide resolved
packages/camera/camera_android_camerax/test/aspect_ratio_strategy_test.dart
Show resolved
Hide resolved
packages/camera/camera_android_camerax/test/resolution_selector_test.dart
Show resolved
Hide resolved
packages/camera/camera_android_camerax/lib/src/resolution_strategy.dart
Outdated
Show resolved
Hide resolved
@immutable | ||
class ResolutionStrategy extends JavaObject { | ||
/// Construct a [ResolutionStrategy]. | ||
ResolutionStrategy({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about making the arguments to this constructor non-null (as they are for the android class) and instead using a private named constructor instead for the creation of the highest available strategy?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love this idea. Changed it and added tests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe as is, it is still nullable (it is required
but someone can still pass null).
I think this can be changed to required Size this.boundSize
, though, to keep it as an initializing formal but just with a stricter (non-nullable) type.
See the "NOTE: Also note that it is possible to enforce a type that is stricter"... in https://dart.dev/tools/linter-rules/prefer_initializing_formals (can't link sections unfortunately).
Left some comments but mostly looks good to me! Main things I'm wondering about are the comment about the constructor for resolution strategy and the question about how we are handling named constants. Other than that it's just comment nits and requests for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just one more comment about the ResolutionStrategy constructor, and a couple of comment nits!
...camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java
Outdated
Show resolved
Hide resolved
...camerax/android/src/main/java/io/flutter/plugins/camerax/AspectRatioStrategyHostApiImpl.java
Outdated
Show resolved
Hide resolved
@immutable | ||
class ResolutionStrategy extends JavaObject { | ||
/// Construct a [ResolutionStrategy]. | ||
ResolutionStrategy({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe as is, it is still nullable (it is required
but someone can still pass null).
I think this can be changed to required Size this.boundSize
, though, to keep it as an initializing formal but just with a stricter (non-nullable) type.
See the "NOTE: Also note that it is possible to enforce a type that is stricter"... in https://dart.dev/tools/linter-rules/prefer_initializing_formals (can't link sections unfortunately).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@@ -116,10 +116,6 @@ class AndroidCameraCameraX extends CameraPlatform { | |||
@visibleForTesting | |||
CameraSelector? cameraSelector; | |||
|
|||
/// The resolution preset used to create a camera that should be used for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this a breaking change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it wasn't used before
/// options. | ||
/// | ||
/// See https://developer.android.com/reference/androidx/camera/core/resolutionselector/AspectRatioStrategy#FALLBACK_RULE_AUTO(). | ||
static const int fallbackRuleAuto = 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider bumping these constants to the top of the class for easier discoverability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would go against the pattern I've been following but if you have strong opinions I can follow this up with another PR moving all static constants to the top of their respective classes
/// * Update `LiveDataHostApiImpl#getValue` is updated to properly return | ||
/// identifiers for instances of type S. | ||
/// * Update `ObserverFlutterApiWrapper#onChanged` to properly handle receiving | ||
/// calls with instances of type S if a LiveData<S> instance is observed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this be removed?
…for image capture, image analysis, and preview (flutter/packages#4523)
flutter/packages@f4ae933...10aab44 2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579) 2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523) 2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851) 2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@f4ae933...10aab44 2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579) 2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523) 2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851) 2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
flutter/packages@f4ae933...10aab44 2023-07-28 [email protected] remove unneeded imports (flutter/packages#4579) 2023-07-27 [email protected] [camerax] Wrap classes to implement resolution configuration for image capture, image analysis, and preview (flutter/packages#4523) 2023-07-27 [email protected] [camera_android] Provides a default exposure point if null. (flutter/packages#3851) 2023-07-27 [email protected] Roll Flutter from 61fd11d to dd9764e (5 revisions) (flutter/packages#4577) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages-flutter-autoroll Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Flutter: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://bugs.chromium.org/p/skia/issues/entry?template=Autoroller+Bug Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Wraps classes to implement resolution configuration for image capture, image analysis, and preview. Also bumps CameraX version to latest and removes the deprecated classes used previously.
No functionality changes. Also thanks to @bparrishMines who did majority of the work here!
Part of flutter/flutter#120462
Pre-launch Checklist
dart format
.)[shared_preferences]
pubspec.yaml
with an appropriate new version according to the pub versioning philosophy, or this PR is exempt from version changes.CHANGELOG.md
to add a description of the change, following repository CHANGELOG style.///
).