Skip to content

Commit

Permalink
Add example to preview composable in layout editor via tools:composab…
Browse files Browse the repository at this point in the history
…leName (#123)

* Add example to preview composable in layout editor via tools:composableName

* Apply Spotless

---------

Co-authored-by: arriolac <[email protected]>
  • Loading branch information
2 people authored and secondsun committed Jul 20, 2023
1 parent 3998e98 commit 821b6c3
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ import com.example.compose.snippets.R
import com.example.compose.snippets.databinding.ExampleLayoutBinding
import com.example.compose.snippets.databinding.FragmentExampleBinding
import com.example.compose.snippets.databinding.MyFragmentLayoutBinding
import com.example.compose.snippets.tooling.Preview

// [START android_compose_interop_apis_compose_in_views]
class ExampleActivity : ComponentActivity() {
Expand Down Expand Up @@ -313,3 +314,11 @@ fun HomeScreen() {
/* Rest of the HomeScreen */
}
// [END android_compose_interop_apis_broadcast_receivers]

// [START android_compose_interop_apis_layout_preview_composable]
@Preview
@Composable
fun GreetingPreview() {
Greeting(name = "Android")
}
// [END android_compose_interop_apis_layout_preview_composable]
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ Copyright 2023 The Android Open Source Project
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
~
-->
<!-- [START android_compose_interop_layout_preview_composable] -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<androidx.compose.ui.platform.ComposeView
android:id="@+id/my_compose_view"
tools:composableName="com.example.compose.snippets.interop.InteroperabilityAPIsSnippetsKt.GreetingPreview"
android:layout_height="match_parent"
android:layout_width="match_parent"/>

</LinearLayout>
<!-- [END android_compose_interop_layout_preview_composable] -->

0 comments on commit 821b6c3

Please sign in to comment.