compose-samples | Official Jetpack Compose samples | Android library

 by   android Kotlin Version: v2023.05.01 License: Apache-2.0

kandi X-RAY | compose-samples Summary

kandi X-RAY | compose-samples Summary

compose-samples is a Kotlin library typically used in Mobile, Android applications. compose-samples has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

This repository contains a set of individual Android Studio projects to help you learn about Compose in Android. Each sample demonstrates different use cases, complexity levels and APIs. For more information, please read the documentation.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              compose-samples has a medium active ecosystem.
              It has 16089 star(s) with 3931 fork(s). There are 346 watchers for this library.
              There were 2 major release(s) in the last 12 months.
              There are 6 open issues and 324 have been closed. On average issues are closed in 53 days. There are 6 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of compose-samples is v2023.05.01

            kandi-Quality Quality

              compose-samples has 0 bugs and 0 code smells.

            kandi-Security Security

              compose-samples has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              compose-samples code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              compose-samples is licensed under the Apache-2.0 License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              compose-samples releases are available to install and integrate.
              Installation instructions are not available. Examples and code snippets are available.
              It has 26812 lines of code, 790 functions and 374 files.
              It has low code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of compose-samples
            Get all kandi verified functions for this library.

            compose-samples Key Features

            No Key Features are available at this moment for compose-samples.

            compose-samples Examples and Code Snippets

            No Code Snippets are available at this moment for compose-samples.

            Community Discussions

            QUESTION

            Maps in Jetpack compose
            Asked 2022-Feb-09 at 06:42

            I'm trying to get a simple map as my mainActivity to test how maps with compose works. Unfortunately I just fail at the beginning with an Errormessage which says basically nothing but "IllegalStateException". I've tried to extract the map code from the original Google example here: https://github.com/android/compose-samples/tree/main/Crane I've tried to rebuild a simple Composable, made an API Key at Google Cloud Platform and added it to my manifest.

            Thats the MainActivity:

            ...

            ANSWER

            Answered 2021-Nov-14 at 18:43

            I don't know if you are reading this, but you have forgotten to include ON_START event for lifecycle, so you are throwing the exception. Also you are calling onStart on ON_CREATE.

            Also consider populating the lifecycleObserver to be scoped into the DisposableEffect and make the DisposableEffect also aware of the mapView (give it as an argument).

            Source https://stackoverflow.com/questions/69540044

            QUESTION

            Not showing Deploy Preview button in Android Studio for com.android.library modules
            Asked 2022-Feb-04 at 20:26

            I'm probably missing something obvious but I'm unable to show the Deploy Preview button in my Android Studio.

            However if I open the Android Compose Samples I see them.

            I checked their dependencies and applied them to my app, but I'm still not able to see them.

            ...

            ANSWER

            Answered 2022-Feb-04 at 11:21

            Did you enable it on the experimental panel in AS settings?

            Also, I believe you're missing the preview dependency implementation "androidx.compose.ui:ui-tooling-preview:$compose_version"

            Source https://stackoverflow.com/questions/70984748

            QUESTION

            Why is a wrapper necessary for a LiveData value?
            Asked 2022-Jan-20 at 17:26

            I was looking at the JetSurvey project (Android Jetpack Compose sample project) and noticed that they created a class to wrap the LiveData value in their ViewModel class. Here is the class I'm talking about:

            ...

            ANSWER

            Answered 2022-Jan-20 at 17:26

            Suppose your LiveData observer in a Fragment navigates to a second Fragment. The user rotates the screen so the first Fragment instance is destroyed. When they back out of the second Fragment, a new instance of the first Fragment is recreated, so its observer is triggered again. Without the event wrapper, it would suddenly and surprisingly navigate back to the second Fragment immediately.

            Also, a LiveData might have multiple observers. Maybe two different Fragments are observing the same events LiveData, but you don't want to risk showing the user a message twice for the same event. For example, they could navigate to a second Fragment that is observing the same events LiveData as the first Fragment. An event fires and the second Fragment observer shows the user a dialog box or something. Then the user backs up to the first Fragment and that same event will fire the first Fragment's observer so the event gets handled twice.

            If your project uses coroutines, a cleaner solution for this event observing problem is to use a SharedFlow with replay of 0 instead of using a LiveData with an event wrapper class. I suspect the reason they didn't use SharedFlow in the JetSurvey project is that they don't want to assume you're already familiar with Flows when that's not what the example is about.

            An alternate solution called SingleLiveEvent appeared in an official Android example once, but was considered too hacky to add to the Jetpack libraries.

            Source https://stackoverflow.com/questions/70790138

            QUESTION

            Navigating with Compose not working with Google Maps on Android
            Asked 2022-Jan-01 at 03:00

            I have a composable containing a google maps view. When I click on a pin on the map I would like to trigger navController.navigate so I can navigate to another composable. However, when I call it the application gets stuck instead of navigating. Navigating on a button clicks works as expected.

            I have also created a very simple application that is demonstrating the problem. The MainActivity looks like this:

            ...

            ANSWER

            Answered 2021-Dec-08 at 19:38

            After some debugging, I come to the conclusion that the problem is somehow related to Lifecycle.Event.ON_STOP -> mapView.onStop() getMapLifecycleObserver

            Removing it solves the problem.

            I'm not happy with the solution and would be happy if someone is able to provide a better solution, or at least an answer explaining more details about the problem.

            Source https://stackoverflow.com/questions/70279262

            QUESTION

            Composable function as a private inner method in Activity
            Asked 2021-Dec-09 at 10:05

            I have started to learn Jetpack compose. I was checking this sample from Google : https://github.com/android/compose-samples/blob/main/Crane/app/src/main/java/androidx/compose/samples/crane/home/MainActivity.kt

            As you see MainScreen composable function is a method in the file and not an inner function in MainActivity class. MainScreen has not been used anywhere else. So why not define it as a private inner function in the Activity?

            Would you please describe me the reason of that?

            ...

            ANSWER

            Answered 2021-Dec-09 at 10:05

            They only need to be defined outside of a class if you plan on using the @Preview annotation, which allows Android Studio to render the composable in a preview pane. They should also be defined outside of the class if you plan on reusing the composable elsewhere in your app or make them generally reusable for other apps.

            You can however define it as a inner function if you want to but you can't use the @Preview annotation. Nevertheless, if you don't plan on using preview and you have no reason to reuse the composable outside of the class, you can define it as an inner function. I've done that on many composables.

            Source https://stackoverflow.com/questions/70287710

            QUESTION

            App made with JetPack Compose is hanging beyond expectation
            Asked 2021-Nov-27 at 04:37

            I am new to JetPack Compose. I am leanring Compose and was following https://developer.android.com/jetpack/compose/tutorial


            But when I ran the application in my android device, the app was extremely slow. Simple things like expanding long message and changing color of message is taking so much time.

            I have googled the problem and found:

            1. https://www.reddit.com/r/androiddev/comments/oatiur/why_simple_app_with_jetpack_compose_is_5x_times/
            2. https://github.com/android/compose-samples/issues/21
            3. https://jetc.dev/slack/2021-03-14-why-so-slow.html
            4. Jetpack Compose Performance Issue that only occurs in multi module project


            But none of these were helpful to me.

            If there is any confusion, please tell in the comments.

            ...

            ANSWER

            Answered 2021-Nov-27 at 04:37

            I experienced the same thing. What is currently happening is:-

            1.) App Startup is kinda slow
            2.) App is glitchy upon start

            The good news is:-

            1.) The glitches only happen for the first few times you run the animation,
            2.) The glitches seem to disappear from every element after you break one of the elements in.

            The bad news is of course, you have to repeat the above steps upon EVERY startup. I have heard that running the production builds instead of the debug variants boosts up the performance significantly. As of now, there's nothing you can do about it. It will only break in as Compose develops. You can check the official Compose Samples too. They are as glitchy as your apps.

            All you can really do at this point is wait.

            EDITS BASED ON THE COMMENTS BELOW:-

            1.) By The glitches seem to disappear from every element after you break one of the elements in., I mean that if you have a lot of animated content, like maybe two LazyColumns, and a few others, then upon swiping the Column back and forth a few times (breaking it in), the lag will be gone from the other columns, as well as the animated content. Element there meant element of the screen, so individual LazyColumns are each elements.

            2.) To get the production build, all you need to do is click on the release tab in the left edge of the screen in studio, then select release from the dropdown list instead of debug. 'Production' was substituted by me for 'release', but it's one and the same thing you see.

            Source https://stackoverflow.com/questions/70120249

            QUESTION

            Do I need to destory a StateFlow object created in view model manually?
            Asked 2021-Oct-29 at 08:00

            The Code A is from a Android offical sample project here.

            The author create a val uiState, it's MutableStateFlow, I know that MutableStateFlow is hot flow, it will occupy system resource when it is created.

            Do I need to destory a StateFlow object created in view model by myself? will the system release it automatically when the app doesn't need it again?

            Code A

            ...

            ANSWER

            Answered 2021-Oct-29 at 06:49

            It's a normal object and as such will be cleaned up once there are no references to it (so when both observing view and ViewModel seizes to exist)

            Source https://stackoverflow.com/questions/69762710

            QUESTION

            Why can't a State variable fire UI update when it is assigned by a new value?
            Asked 2021-Oct-27 at 06:56

            The Code A is based a Android offical sample project here.

            The Code A can display correct data in UI.

            If I use Code B, I find that nothing is displayed.

            It seems that _uiState=_uiState.copy(...) doesn't make uiState to notice UI that the data has changed in Code B.

            What is wrong with Code B?

            Code A

            ...

            ANSWER

            Answered 2021-Oct-27 at 06:52

            I don't see your pattern described in the official docs:

            https://developer.android.com/jetpack/compose/state

            It is possible it worked under an older version of Compose and doesn't work under the current version??

            According to the docs, recomposition can only occur when you use mutableStateOf in conjunction with a remember and set the value property to a new value to trigger the recomposition:

            Source https://stackoverflow.com/questions/69733447

            QUESTION

            Why can't I use State in ViewModel directly with Android Studio?
            Asked 2021-Oct-27 at 03:20

            The Code A is from offical sample project here.

            The InterestsViewModel define uiState as StateFlow, and it is converted as State by collectAsState() in the Composable function rememberTabContent.

            I'm very strange why the author doesn't define uiState as State directly in InterestsViewModel, so I write Code B.

            The Code B can be compiled , and it can run, but it display nothing in screen, what is wrong with Code B ?

            Code A

            ...

            ANSWER

            Answered 2021-Oct-27 at 03:20

            The uiState that you are using in your Composable val uiState: InterestsUiState = _uiState is not a State and hence doesn't respond to changes. It's just a normal InterestsUiState initialized with the current value of _uiState. To make it work, you can simply expose the getter for _uiState.

            Source https://stackoverflow.com/questions/69732128

            QUESTION

            What is assigned to the variable updateSection in the offical sample code?
            Asked 2021-Oct-26 at 04:25

            The Code A is from offical sample code here.

            val (currentSection, updateSection) = rememberSaveable { mutableStateOf(tabContent.first().section) } is a destructuring declaration.

            It's a clear that currentSection is assigned by tabContent.first().section

            What is assigned to the variable updateSection? Will it be assigned by tabContent.first().content ?

            Code A

            ...

            ANSWER

            Answered 2021-Oct-26 at 04:25

            updateSection is a lambda here used to update the value of the mutable state. Consider this example:

            Source https://stackoverflow.com/questions/69717113

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install compose-samples

            You can download it from GitHub.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/android/compose-samples.git

          • CLI

            gh repo clone android/compose-samples

          • sshUrl

            git@github.com:android/compose-samples.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link