Skip to content

Migrate CameraX platform sample to new architecture#139

Merged
vkatz merged 1 commit intomainfrom
task/camerax-android-sample
Mar 18, 2025
Merged

Migrate CameraX platform sample to new architecture#139
vkatz merged 1 commit intomainfrom
task/camerax-android-sample

Conversation

@egorikftp
Copy link
Member

Ref: #137

Copy link

@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 @egorikftp, 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

This pull request migrates the CameraX platform sample to a new architecture. It introduces a new screen, AndroidViewLifecycleScreen, which demonstrates the usage of CameraX with lifecycle handling in a Compose application. The changes include adding necessary dependencies for CameraX, requesting camera permissions, and implementing a basic camera preview using AndroidView and PreviewView.

Highlights

  • CameraX Integration: Integrates CameraX library for camera functionality within the Android platform sample.
  • Permission Handling: Implements runtime permission handling for camera access using rememberLauncherForActivityResult.
  • UI Implementation: Creates a composable UI for displaying the camera preview and handling camera lens switching.
  • Lifecycle Management: Demonstrates lifecycle integration with CameraX to properly manage camera resources.

Changelog

Click here to see the changelog
  • example/app/composeApp/src/androidMain/AndroidManifest.xml
    • Removed camera feature and permission declarations from the main AndroidManifest.xml.
  • example/platform/build.gradle.kts
    • Added dependencies for CameraX (camera2, lifecycle, view) and androidx.concurrent.futures.
  • example/platform/src/androidMain/AndroidManifest.xml
    • Added a new AndroidManifest.xml file to the platform module, declaring camera feature and permission.
  • example/platform/src/androidMain/kotlin/composegears/tiamat/example/platform/AndroidViewLifecycleScreen.kt
    • Created a new composable screen AndroidViewLifecycleScreen to demonstrate CameraX integration.
    • Implemented permission request and handling for camera access.
    • Added a CameraView composable to display the camera preview using PreviewView.
    • Implemented lens facing switching functionality.
    • Added UI elements for taking a photo (with a Toast message as a placeholder).
  • example/platform/src/androidMain/kotlin/composegears/tiamat/example/platform/Platform.android.kt
    • Added a new AppFeature for CameraX to the list of platform features.
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.


Did you know?

The first camera phone was invented in 1997 by Philippe Kahn, who instantly shared the first photo - of his newborn daughter - with over 2,000 family and friends.

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

@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

The pull request migrates the CameraX platform sample to a new architecture, which involves adding necessary dependencies, permissions, and implementing a CameraView using AndroidView and Compose. The code is well-structured and addresses the issue of integrating CameraX with Compose in a multiplatform project. However, there are a few areas that could be improved for better clarity and efficiency.

Summary of Findings

  • Redundant Permission Declaration: The camera permission is declared in both the main AndroidManifest.xml and the platform-specific AndroidManifest.xml. This redundancy should be addressed by removing the declaration from the main manifest to avoid confusion and potential conflicts.
  • Lifecycle State Observation: The lifecycle state is being observed but not actively used. Consider leveraging the lifecycle state to optimize camera operations, such as pausing or resuming the camera based on the lifecycle state.
  • Potential Memory Leak: The previewView is created using remember { PreviewView(context) }. While remember helps retain the instance across recompositions, it's essential to ensure that the previewView is properly released when the composable is disposed of to prevent potential memory leaks.

Merge Readiness

The pull request introduces a valuable feature by integrating CameraX with Compose in a multiplatform project. However, before merging, it's recommended to address the redundant permission declaration and consider leveraging the lifecycle state for camera operations. While I am unable to directly approve this pull request, addressing these points will improve the code's quality and maintainability. Ensure that other reviewers also approve these changes before merging.

@vkatz vkatz merged commit cae2a9c into main Mar 18, 2025
2 checks passed
@vkatz vkatz deleted the task/camerax-android-sample branch March 18, 2025 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants