Skip to content

Instantly share code, notes, and snippets.

@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
@Farhandroid
Farhandroid / AnimateAsStateExample.kt
Last active August 31, 2023 06:34
AnimateAsStateExample.kt
@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(
@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()
) {
@Farhandroid
Farhandroid / SearchGeneric.swift
Last active April 27, 2022 10:23
SearchGeneric
struct Person: Equatable{
let name: String
let email: String
let age: Int
}
func search() {
let henry = Person(name : "Henry", email : "henry@email.com", age : 24)
let robert = Person(name : "Robert", email : "robert@email.com", age : 22)
let tom = Person(name : "Tom", email : "tom@email.com", age : 25)
@Farhandroid
Farhandroid / SearchUtil.swift
Last active April 27, 2022 10:22
SearchUtil
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
@Farhandroid
Farhandroid / BindingAdapter.kt
Created April 15, 2022 14:52
BindingAdapter
object BindingAdapter {
@BindingAdapter("loadImageFromUrl")
@JvmStatic
fun loadImageFromUrl(imageView: ImageView, imageUrl: String) {
imageView.load(imageUrl) {
crossfade(600)
error(R.drawable.ic_error_placeholder)
}
}
}
@Farhandroid
Farhandroid / fragment_image_viewer.xml
Created April 15, 2022 07:11
fragment_image_viewer
<?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"
@Farhandroid
Farhandroid / MemoryLeakImageSearchFragment.kt
Created March 30, 2022 06:53
MemoryLeakImageSearchFragment
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
@Farhandroid
Farhandroid / ComposableWithoutState.kt
Created March 23, 2022 08:18
ComposableWithoutState
@Composable
fun Content() {
Column(modifier = Modifier.padding(16.dp)) {
Text(
text = "Hello,",
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.h5
)
OutlinedTextField(
value = "",
@Farhandroid
Farhandroid / ComposableState.kt
Created March 23, 2022 08:17
ComposableState
@Composable
fun Content() {
var name by remember { mutableStateOf("") }
Column(modifier = Modifier.padding(16.dp)) {
Text(
text = "Hello, $name",
modifier = Modifier.padding(bottom = 8.dp),
style = MaterialTheme.typography.h5
)
OutlinedTextField(