This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun InteractiveScreen(snackbarHostState: SnackbarHostState) { | |
// Remember a CoroutineScope tied to the lifecycle of InteractiveScreen | |
val scope = rememberCoroutineScope() | |
Column(Modifier.padding(16.dp)) { | |
Button(onClick = { | |
// Launch a coroutine when the button is clicked | |
scope.launch { | |
snackbarHostState.showSnackbar("Action triggered!") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun MainScreen(viewModel: NewsViewModel) { | |
// LaunchedEffect to fetch news when the MainScreen is first composed | |
LaunchedEffect(Unit) { | |
viewModel.fetchNews() // `fetchNews` is a suspend function implemented in ViewModel | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun CustomAnimationExample() { | |
val offset = remember { Animatable(0f) } | |
val coroutineScope = rememberCoroutineScope() | |
var isUpwards by remember { mutableStateOf(true) } | |
Column { | |
Button(onClick = { | |
coroutineScope.launch { | |
val target = if (isUpwards) 300f else 0f |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun AnimateAsStateExample() { | |
// State to control the background color | |
var boxColor by remember { mutableStateOf(Color.Blue) } | |
// Animate the background color | |
val backgroundColor by animateColorAsState(targetValue = boxColor, label = "") | |
// Box with clickable modifier to change the color | |
Box( |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Composable | |
fun AnimatedVisibilityExample() { | |
// State to control the visibility of the text | |
var isVisible by remember { mutableStateOf(true) } | |
// Box to layer the button and the text | |
Box( | |
contentAlignment = Alignment.Center, | |
modifier = Modifier.fillMaxSize() | |
) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct Person: Equatable{ | |
let name: String | |
let email: String | |
let age: Int | |
} | |
func search() { | |
let henry = Person(name : "Henry", email : "[email protected]", age : 24) | |
let robert = Person(name : "Robert", email : "[email protected]", age : 22) | |
let tom = Person(name : "Tom", email : "[email protected]", age : 25) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchUtil{ | |
var list: [Int] = [] | |
init(list: [Int]) { | |
self.list = list | |
} | |
func searchItem(element: Int, foundItem: (Int?)->()) { | |
let itemFoundList = self.list.filter { item in | |
item == element |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
object BindingAdapter { | |
@BindingAdapter("loadImageFromUrl") | |
@JvmStatic | |
fun loadImageFromUrl(imageView: ImageView, imageUrl: String) { | |
imageView.load(imageUrl) { | |
crossfade(600) | |
error(R.drawable.ic_error_placeholder) | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<layout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
tools:context=".presentation.image_viewer.ImageViewerFragment"> | |
<data> | |
<variable | |
name="imageSrc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ImageSearchFragment : Fragment() { | |
private var _binding: FragmentImageSearchBinding? = null | |
private val binding get() = _binding!! | |
override fun onCreateView( | |
inflater: LayoutInflater, container: ViewGroup?, | |
savedInstanceState: Bundle?, | |
): View? { | |
// Inflate the layout for this fragment |
NewerOlder