Skip to content

Conversation

@MagicalMeghan
Copy link
Contributor

Adding a few CameraX compose fixes

CameraX fixes
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 Modifier parameters are handled and passed down through several composables, including CameraXBasic, ContentWithPermissionHandling, CameraPermissionDeniedView, CameraPreviewContent, and CapturedImageView. 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 CameraPreviewContent composable has been simplified by removing an unnecessary Column wrapper and applying alignment and padding directly to the Button's modifier.
  • CapturedImageView API Change: The onDismiss callback parameter in the CapturedImageView composable 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 wrapContentSize and viewModel imports.
    • Adjusted modifier application in CameraXBasic to apply the external modifier to the root Box.
    • Modified the call to ContentWithPermissionHandling to pass Modifier instead of the external modifier.
    • Passed the modifier parameter down to the CapturedImageView call within ContentWithPermissionHandling.
    • Passed the modifier parameter down to the CameraPermissionDeniedView call within ContentWithPermissionHandling and added named parameters to the call.
    • Added a modifier parameter to the CameraPermissionDeniedView function signature and applied it to the root Column.
    • Applied the modifier parameter to the root Box in CameraPreviewContent.
    • Simplified the layout for the 'Take Photo' button in CameraPreviewContent by removing the Column wrapper.
    • Added a modifier parameter to the CapturedImageView function signature, applied it to the root Box, and made the onDismiss parameter optional.
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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 modifier parameters in child composables like CapturedImageView, CameraPermissionDeniedView, and CameraPreviewContent.
  • Clarification of modifier responsibilities, where the modifier passed to CameraXBasic styles its root container, and internal components manage their own modifiers starting from a clean Modifier instance.
  • Simplification by removing a redundant Column wrapper 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 CameraPreviewContent incorrectly chains its layout modifiers from the parent composable's modifier parameter. This could lead to unexpected styling if the parent composable is reused with custom modifiers. The button should use its own Modifier chain for alignment and padding.
  • Unused Import: The import androidx.lifecycle.viewmodel.compose.viewModel is 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.

Comment on lines 273 to 275
modifier
.align(Alignment.BottomCenter)
.padding(16.dp),
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

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?

Suggested change
modifier
.align(Alignment.BottomCenter)
.padding(16.dp),
modifier = Modifier
.align(Alignment.BottomCenter)
.padding(16.dp),

viewModel = viewModel,
imageCaptureCallbackExecutor = imageCaptureCallbackExecutor,
modifier = modifier,
modifier = Modifier,

Choose a reason for hiding this comment

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

Just omit this

Copy link

@nickbutcher nickbutcher left a 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.

@MagicalMeghan MagicalMeghan merged commit 37335ea into main May 21, 2025
5 of 7 checks passed
@MagicalMeghan MagicalMeghan deleted the camerax-fix branch May 21, 2025 19:04
Copy link

@mr-adonisjimenez mr-adonisjimenez left a comment

Choose a reason for hiding this comment

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

🏆

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants