Welcome back.
We created that camera permission wrapper.
Now let's create the camera preview inside the screens.
Create a new file, name it as camera preview.
Create a new composable function named as camera Preview and pass two parameters modifier.
It's of type modifier and set the modifier equals to the modifier as initial and as a default and on
image analysis.
Image analysis.
And it's a lambda function that takes an image analysis as parameter and returns a unit as a callback.
Okay, so let me start by val context equals to local context dot concurrent.
We are getting the context val life cycle owner equals to the local life cycle owner dot.
Okay.
Those variables, we talked a lot about them in the previous applications.
Val camera provider future equals to remember.
And here we need to process camera provider dot get instance process camera provider.
It's from camera dot lifecycle package.
Here we are starting the usage of camera X okay.
So camera provider future gets the camera provider instance manages the camera lifecycle.
This is a very important note.
You should pay attention to it.
Camera provider future gets the camera provider instance and that manages the camera lifecycle.
Then we need to create another variable called image capture.
So here we need to handle the state state for capturing still photos.
How to create this variable is very simple image capture.
It's of type image capture that is used for capturing still by and the mutable.
We are handling the state of the image.
Capture Alt+ enter to import the by and import the mutable dot get value.
Then we need another variable, the preview state for camera preview display.
Similar to what we've created.
What we've done here var preview by remember mutable state of and it's of type preview.
Import the preview from Android X camera.
And this is good.
Now we need to create the executor.
Val executor equals to the context compat dot get main executor context.
This is the main thread executor for camera callbacks because we need to use it inside the main thread.
The last thing we need to create is the camera provider.
This is the actual camera provider from the future and this is done by val camera provider.
Equals to camera provider dot get.
The purpose of creating executor camera provider preview, image capture and camera provider is to initialize
camera components needed for camera functionality and this uses reactive state so UI updates when camera
components are ready.
Prepares the infrastructure for showing camera preview here.
Taking pictures using the image capture and managing camera lifecycle using the camera provider.
This sets up the foundation for camera operations in a compose friendly way.