-
Notifications
You must be signed in to change notification settings - Fork 470
Update CameraXBasic.kt #299
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
Conversation
CameraX fixes
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.
Hello @MagicalMeghan, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
Summary of Changes
Hello team, gemini-code-assist here to provide a summary of this pull request. This PR, authored by MagicalMeghan, focuses on making several fixes and improvements to the CameraX basic sample using Jetpack Compose. The primary goal appears to be enhancing the flexibility and correctness of how modifiers are applied to various composable functions within the sample, as well as making a minor layout adjustment and an API tweak.
Highlights
- Modifier Handling: The pull request refactors how
Modifierparameters are handled and passed down through several composables, includingCameraXBasic,ContentWithPermissionHandling,CameraPermissionDeniedView,CameraPreviewContent, andCapturedImageView. This allows external modifiers to be applied correctly to the root elements of these composables, improving their reusability. - Layout Simplification: The layout for the 'Take Photo' button in the
CameraPreviewContentcomposable has been simplified by removing an unnecessaryColumnwrapper and applying alignment and padding directly to theButton's modifier. - CapturedImageView API Change: The
onDismisscallback parameter in theCapturedImageViewcomposable has been made optional with a default empty lambda, providing more flexibility when using this composable.
Changelog
- samples/camera/camerax/src/main/java/com/example/platform/camerax/basic/CameraXBasic.kt
- Added
wrapContentSizeandviewModelimports. - Adjusted modifier application in
CameraXBasicto apply the external modifier to the rootBox. - Modified the call to
ContentWithPermissionHandlingto passModifierinstead of the external modifier. - Passed the
modifierparameter down to theCapturedImageViewcall withinContentWithPermissionHandling. - Passed the
modifierparameter down to theCameraPermissionDeniedViewcall withinContentWithPermissionHandlingand added named parameters to the call. - Added a
modifierparameter to theCameraPermissionDeniedViewfunction signature and applied it to the rootColumn. - Applied the
modifierparameter to the rootBoxinCameraPreviewContent. - Simplified the layout for the 'Take Photo' button in
CameraPreviewContentby removing theColumnwrapper. - Added a
modifierparameter to theCapturedImageViewfunction signature, applied it to the rootBox, and made theonDismissparameter optional.
- Added
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Compose builds the UI,
Modifiers shape and align,
Fixing layout bugs.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces several good refinements to CameraXBasic.kt, primarily focusing on improving how Jetpack Compose Modifiers are handled and propagated through the composable hierarchy. The changes generally lead to cleaner, more consistent, and more idiomatic Compose code.
Key improvements include:
- Consistent use of
modifierparameters in child composables likeCapturedImageView,CameraPermissionDeniedView, andCameraPreviewContent. - Clarification of modifier responsibilities, where the
modifierpassed toCameraXBasicstyles its root container, and internal components manage their own modifiers starting from a cleanModifierinstance. - Simplification by removing a redundant
Columnwrapper around the "Take Photo" button. - Use of named arguments and default parameter values, enhancing readability and API flexibility.
I've found one medium-severity issue related to modifier usage on a Button that should be addressed. Other than that, the changes are positive.
Summary of Findings
- Modifier Usage on Button: The 'Take Photo' button in
CameraPreviewContentincorrectly chains its layout modifiers from the parent composable'smodifierparameter. This could lead to unexpected styling if the parent composable is reused with custom modifiers. The button should use its ownModifierchain for alignment and padding. - Unused Import: The import
androidx.lifecycle.viewmodel.compose.viewModelis added but not used in the file. This was not commented on directly due to review settings for low-severity issues.
Merge Readiness
The pull request introduces valuable improvements to modifier handling and code clarity. However, there is one medium-severity issue regarding modifier usage on a button within CameraPreviewContent that should be addressed to ensure robustness and prevent potential styling bugs if the component is reused in different contexts.
Once this issue is resolved, the PR should be in good shape for merging. As a reviewer, I am not authorized to approve the pull request, so please ensure it undergoes further review and approval as per your team's process.
| modifier | ||
| .align(Alignment.BottomCenter) | ||
| .padding(16.dp), |
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.
The Button's modifier is currently chaining off the modifier parameter of the CameraPreviewContent composable (modifier.align(...).padding(...)).
While this might work by coincidence in the current setup (where CameraPreviewContent's modifier parameter effectively resolves to Modifier), it's conceptually incorrect. The modifier parameter of CameraPreviewContent is intended for styling the CameraPreviewContent component as a whole (e.g., its root Box), not for dictating the specific layout modifiers of its internal children like this Button.
If CameraPreviewContent were ever called with a non-default modifier (e.g., Modifier.background(Color.Red)), that modifier would unintentionally be applied to this Button before the .align and .padding modifiers.
The Button's layout modifiers (.align and .padding) should be self-contained, starting from a fresh Modifier instance to ensure proper encapsulation and prevent unexpected styling side effects.
Could we change this to start with Modifier for the button's specific layout needs?
| modifier | |
| .align(Alignment.BottomCenter) | |
| .padding(16.dp), | |
| modifier = Modifier | |
| .align(Alignment.BottomCenter) | |
| .padding(16.dp), |
| viewModel = viewModel, | ||
| imageCaptureCallbackExecutor = imageCaptureCallbackExecutor, | ||
| modifier = modifier, | ||
| modifier = Modifier, |
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 omit this
nickbutcher
left a comment
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.
One small comment but otherwise LGTM.
mr-adonisjimenez
left a comment
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.
🏆
Adding a few CameraX compose fixes