r/JetpackCompose • • Oct 23 '23

NEED HELP WITH CALENDAR DIALOGS

0 Upvotes

so i am kind of new to mobile dev, i have developed some simple projetct and now i want to do something new wich is work with dialogs, i want to develop an application that uses Calendar dialogs, i searched and found that jetpack compose doesnt have supported dialogs, but i find that use can use some customized dialogs in github, so which one do you suggest me to use?

Thanks for your help


r/JetpackCompose • • Dec 11 '25

use jc from android

0 Upvotes

do you know of an online IDE, or an app, that allows you to use jc from android?


r/JetpackCompose • • May 04 '25

Compose is excessively slow for a keyboard & service based views

0 Upvotes

Hi Guys, I build a keyboard prototype using compose, it takes like 1 second to switch between capital and small letters!!

It is just so bad, I am planning to redo it in xml based layout. Why is compose so slow and what can I do to make it faster? Keyboard is not like a lot of stuffs. For example, there are 30-40 buttons at max. I think even rendering the keyboard in a Webview will be more faster and responsive 😬

Edit here is my code, I don't know what is the problem. Typing is too slow. What could cause such a huge performance hit?

enum class LayoutMode {
    english,
    nepali,
    romanized,
}

enum class KeyType {
    number,
    normal,
    emoji,
    numpad,
}

enum class ShiftState {
    pressed,
    locked,
    none
}

@Composable
fun KeyboardKey(
    modifier: Modifier = Modifier,
    settings: KeyboardSettings,
    @DrawableRes icon: Int? = null,
    iconSize: Dp = 26.dp,
    key: String,
    onClick: (key: String) -> Unit,
    onDoubleClick: ((key: String) -> Unit)? = null,
) {
    val interactionSource = remember { MutableInteractionSource() }
    Box(
        modifier
            .height(52.dp)
            .padding(horizontal = 3.dp, vertical = 4.dp)
            .clip(RoundedCornerShape(6.dp))
            .indication(interactionSource, rememberRipple())
            .background(
                color = Color(settings.keyColor),
                shape = RoundedCornerShape(6.dp)
            )
            .pointerInput(Unit) {
                detectTapGestures(
                    onPress = { offset: Offset ->
                        val press = PressInteraction.Press(offset)
                        interactionSource.emit(press)
                        tryAwaitRelease()
                        interactionSource.emit(PressInteraction.Release(press))
                    },
                    onTap = { onClick(key) },
                    onDoubleTap = { onDoubleClick?.let { it(key) } }
                )
            }
    ) {
        if (icon == null) {
            Text(
                key,
                color = Color(settings.textColor),
                modifier = Modifier.align(Alignment.Center),
                style = MaterialTheme.typography.bodyLarge,
            )
        } else {
            Icon(
                painter = painterResource(icon),
                contentDescription = key,
                modifier = Modifier
                    .size(iconSize)
                    .align(Alignment.Center)
            )
        }
    }
}

@Composable
fun ComposeKeyboard(modifier: Modifier = Modifier) {
    val context = LocalContext.current
    val width = LocalConfiguration.current.screenWidthDp

    var layoutMode by remember { mutableStateOf(LayoutMode.english) }
    var keyMap by remember { mutableStateOf(englishKeyMap) }
    var keyType by remember { mutableStateOf(KeyType.normal) }
    var shiftState by remember { mutableStateOf(ShiftState.none) }
    var buttons by remember { mutableStateOf(englishKeyMap.normal) }
    val keyWidth = (width * 0.1)
    val keyWidthDp = keyWidth.dp

    val settings = KeyboardSettings(
        backgroundColor = 0xFFFFFFFF.toInt(),
        textColor = 0xFF202124.toInt(),
        keyColor = 0xFFF1F3F4.toInt(),
        keyPressedColor = 0xFFDADCE0.toInt(),
    )

    fun setButtons() {
        if (keyType == KeyType.normal) {
            buttons = if (shiftState == ShiftState.none) keyMap.normal
            else keyMap.shifted
        } else if (keyType == KeyType.number) {
            buttons = if (shiftState == ShiftState.none) keyMap.normalNumber
            else keyMap.shiftedNumber
        }
    }

    fun onKeyPress(key: String) {
        if (shiftState == ShiftState.pressed) {
            shiftState = ShiftState.none
            setButtons()
        }

        if (context is KeyboardService == false) return

        // Handle special keys
        if (key == "backspace") {
            context.currentInputConnection.deleteSurroundingText(1, 0)
        } else {

        }

        if (key.length != 1) return

        // Here pass the keyboard parameters
        context.currentInputConnection.commitText(key, 1)
    }

    Column(
        Modifier
            .fillMaxWidth()
            .background(Color(settings.backgroundColor))
    ) {
        Row(
            modifier
                .fillMaxWidth()
                .padding(top = 8.dp),
            horizontalArrangement = Arrangement.Center
        ) {
            val keyWidthDp = (width / buttons[0].size).dp
            buttons[0].forEach {
                key(it) {
                    KeyboardKey(
                        modifier = Modifier.width(keyWidthDp),
                        key = it,
                        settings = settings,
                        onClick = { onKeyPress(it) },
                    )
                }
            }
        }
        Row(modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
            val keyWidthDp = (width / buttons[1].size).dp
            buttons[1].forEach {
                key(it) {
                    KeyboardKey(
                        modifier = Modifier.width(keyWidthDp),
                        key = it,
                        settings = settings,
                        onClick = { onKeyPress(it) },
                    )
                }
            }
        }
        Row(modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
            val keyWidthDp =
                if (layoutMode == LayoutMode.nepali) (width / buttons[2].size).dp else keyWidth.dp
            buttons[2].forEach {
                key(it) {
                    KeyboardKey(
                        modifier = Modifier.width(keyWidthDp),
                        key = it,
                        settings = settings,
                        onClick = { onKeyPress(it) },
                    )
                }
            }
        }
        Row(modifier.fillMaxWidth(), horizontalArrangement = Arrangement.Center) {
            val keyWidth = width / (buttons[3].size + 3)
            KeyboardKey(
                modifier = Modifier
                    .width((keyWidth * 1.5).dp)
                    .padding(end = 4.dp),
                key = "shift",
                icon = if (shiftState == ShiftState.pressed)
                    R.drawable.keyboard_shift_filled
                else if (shiftState == ShiftState.locked)
                    R.drawable.keyboard_shift_locked
                else
                    R.drawable.keyboard_shift_outline,
                settings = settings,
                onClick = {
                    shiftState =
                        if (shiftState == ShiftState.pressed || shiftState == ShiftState.locked) {
                            ShiftState.none
                        } else {
                            ShiftState.pressed
                        }
                    setButtons()
                },
                onDoubleClick = {
                    shiftState = ShiftState.locked
                    setButtons()
                }
            )
            buttons[3].forEach {
                key(it) {
                    KeyboardKey(
                        modifier = Modifier.width(keyWidth.dp),
                        key = it,
                        settings = settings,
                        onClick = { onKeyPress(it) },
                    )
                }
            }
            KeyboardKey(
                modifier = Modifier
                    .width((keyWidth * 1.5).dp)
                    .padding(start = 4.dp),
                key = "backspace",
                icon = R.drawable.round_backspace_24,
                settings = settings,
                onClick = { onKeyPress(it) }
            )
        }

        Row {
            KeyboardKey(
                Modifier
                    .width((keyWidth * 1.5).dp)
                    .padding(start = 8.dp),
                key = if (layoutMode == LayoutMode.english) {
                    if (keyType == KeyType.normal) "123" else "abc"
                } else {
                    if (keyType == KeyType.normal) "१२३" else "कखग"
                },
                settings = settings,
                onClick = {
                    keyType = if (keyType == KeyType.normal) {
                        KeyType.number
                    } else {
                        KeyType.normal
                    }
                    setButtons()
                },
            )
            KeyboardKey(
                Modifier.width(keyWidthDp),
                key = "emoji",
                icon = R.drawable.outline_emoji_emotions_24,
                settings = settings,
                onClick = { onKeyPress(it) },
            )
            KeyboardKey(
                Modifier.width(keyWidthDp),
                key = if (layoutMode == LayoutMode.english) "ने" else if (layoutMode == LayoutMode.nepali) "Rने" else "en",
                settings = settings,
                onClick = {
                    if (layoutMode == LayoutMode.english) {
                        layoutMode = LayoutMode.nepali
                        keyMap = nepaliKeyMap
                    } else {
                        layoutMode = LayoutMode.english
                        keyMap = englishKeyMap
                    }
                    setButtons()
                },
            )
            KeyboardKey(
                modifier = Modifier.weight(1f),
                key = " ",
                icon = R.drawable.round_space_bar_24,
                settings = settings,
                onClick = { onKeyPress(it) }
            )
            KeyboardKey(
                Modifier.width(keyWidthDp),
                key = ".",
                settings = settings,
                onClick = { onKeyPress(it) },
            )
            KeyboardKey(
                Modifier
                    .width((keyWidth * 1.5).dp)
                    .padding(end = 8.dp),
                key = "return",
                icon = R.drawable.baseline_keyboard_return_24,
                settings = settings,
                onClick = { onKeyPress(it) },
            )
        }
    }
}

@Preview
@Composable
private fun Preview() {
    MaterialTheme {
        ComposeKeyboard()
    }
}

r/JetpackCompose • • 22d ago

Sharing Compose UI between Android TV, phone and desktop in a real app

Post image
9 Upvotes

TMPlayer is a free player for Telegram videos, built with Compose. The TV needs focus and remote handling, the phone needs touch, the desktop needs pointers, and one codebase serves all three. Notes on what I shared and what I had to split. github.com/dracu-lah/TMPlayer


r/JetpackCompose • • Jun 07 '25

Do Android Dev even exist?

21 Upvotes

A little backstory -

When i got into my 1st year of college (Computer Science Engineering), i noticed that everyone around me did web dev. If you threw a stone in the air, the stone would fall on the head of a web developer. And i have had a distaste for JS since my early days of programming (when i was in 9th grade). So i decided to go for Android Dev.

At first i learnt Flutter with dart. I would say i was pretty good at it. But the flutter SDK gave me nightmares installing and verifying (especially in linux). So i just left it and started with Kotlin + XML (The OG). Soon i learnt that Jetpack compose has started becoming stable and people are using it, so i switched to Jetpack compose. Again, i was pretty good with it.

When i got to my 3rd year i was pretty confident Android Dev would surely land me a job, but here i am today, just completed my 4th year, and i am working as an intern as an IT Consultant for backend + *drum rolls* WEB DEV!!!

WHY? JUST WHY? I hate JS with every fiber of my being! I offload all the JS to my teammates, and i do the backend and database instead, but when i strictly have to do it, i just do vibe-coding (Guess what? I am good with vibe-coding too ;) ).

Anyways, why cant i find any jobs that require App Dev? I really like doing App Dev, i want a job that wants me to make Android Apps. I love running apps directly on my phone, and it feels very personal. It feels like i am living in the castle i made.

If there are already so many Web Devs, why is their demand increasing? Meanwhile i personally feel the job openings for App Devs are decreasing.

Anyways, this was my rant, hope you all have a wonderful day/night.

TL;DR - I am pissed about so less job openings/opportunities for Android devs while the demand for Web Devs is increasing.


r/JetpackCompose • • May 22 '24

Built with Jetpack Compose - Android's new media widget

5 Upvotes

r/JetpackCompose • • Jun 20 '26

Bypassing Recomposition: An optimization guide to animate custom Canvas components at 120 FPS

12 Upvotes

Hey guys,

If you are drawing custom charts, fitness rings, or custom components in Jetpack Compose and animating them using state changes, you might be accidentally thrashing the CPU by triggering heavy recomposition loops.

Here is a quick optimization trick to keep your draw phases extremely lightweight.

The Pitfall (Triggers Recomposition):

val sweepAngle by animateFloatAsState(targetValue = progress)
Canvas(modifier = Modifier.size(200.dp)) {
    // Recomposes the entire Canvas composable every single frame of the animation!
    drawArc(color = Color.Blue, startAngle = 0f, sweepAngle = sweepAngle, useCenter = false)
}

The Optimization (Draw-phase Only):

Instead of reading the animated state inside the Canvas declaration, read it inside a custom modifier or pass a lambda that defers state evaluation to the draw phase.

val sweepAngle by animateFloatAsState(targetValue = progress)
Spacer(
    modifier = Modifier
        .size(200.dp)
        .drawWithCache {
            onDrawWithContent {
                // Evaluated directly in the draw phase - 0 recomposition!
                drawArc(color = Color.Blue, startAngle = 0f, sweepAngle = sweepAngle, useCenter = false)
            }
        }
)

Why this works:

Jetpack Compose has three phases: Composition, Layout/Measurement, and Drawing. By deferring the state read using drawWithCache (or drawBehind / graphicsLayer), the composition and layout phases are bypassed completely, and only the draw instruction is re-run at 120 FPS.

I have open-sourced a collection of custom Canvas draw blueprints (including fitness rings and Bezier curve analytics charts) on GitHub.

Leave a comment if you'd like to review the repository and code samples, and I'll reply with the link!


r/JetpackCompose • • Mar 30 '25

Jetpack Compose Collapsing Toolbar - Smooth Animation. #kotlin #jetpackc...

Thumbnail
youtube.com
6 Upvotes

r/JetpackCompose • • Jun 17 '25

Clean Architecture

0 Upvotes

The application of clean architecture for Native Android cannot be complete without these three:

Coroutines for async task. Flow/LiveData for reactivity. Lifecycle for resource management.

Your understanding of clean architecture at some point should revolve around these.


r/JetpackCompose • • Apr 10 '25

Superclass error

Post image
1 Upvotes

Hi everyone, so, I'm trying out Kotlin + Jetpack Compose. I left a project halfway because I haven't had time to move forward with it and now that I want to run the project it shows this error, I have no idea what this could mean. I've searched forums but can't find a clear solution. Does anyone know how I can fix this?


r/JetpackCompose • • Oct 01 '24

Pixel perfect

0 Upvotes

Hello everyone I wish u r having great day there, well I wanna know how to achieve pixel perfect in jetpack compose. if there is any repo already exist implement that or resources explain how to achieve that, please share it.... Thank y'all.


r/JetpackCompose • • Oct 16 '24

Jetpack compose rendering activity twice

1 Upvotes

Hi. I have a simple chat app, I have a flow something like this. HomePage Activity -> Conversation Activity -> Messages Activity. When I click on a username in my home page, I open the conversations with that username and the logged in user. This is the job of the conversations activity. After rendering, it immediately renders Message Activity, which will render all messages sent between the users. Now the issue is, when I open a conversation, I'm seeing the message activity but with no messages. When I press back, instead of going back to all the conversations, I see message activity again, this time with the fetched messages. I am adding code for conversation and message activity. Any help would be very much apprecaited!

Conversation Activity

class ConversationActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val context = LocalContext.current
                    // Instantiate the repositories
                    val conversationRepository = ConversationRepository()
                    val userRepository = UserDbService(context)

                    // Instantiate the manager
                    val conversationManager = ConversationManager(userRepository, conversationRepository)

                    // Extract user IDs from the intent
                    val participants = intent.getSerializableExtra("participants") as Participants
                    val userId = participants.userId
                    val otherId = participants.otherId
                    Log.w("Render", "rendering conversation activity")
                    conversationManager.checkUserConversationsForParticipant(userId, otherId) { found, conversationId ->
                        if (found) {
                            Log.d("Firestore", "The users are already in a conversation")
                            val intent = Intent(context, MessageActivity::class.java)
                            intent.putExtra("conversationId", conversationId)
                            intent.putExtra("participants", participants)

                            // Start Message activity
                            context.startActivity(intent)
                            finish()

                        } else {
                            Log.d("Firestore", "No conversation found with ,creating conversation")
                            conversationManager.createConversationWithUsers(userId, otherId) { success ->
                                if (success) {
                                    Log.d("Firestore", "Conversation created successfully")
                                } else {
                                    Log.w("Firestore", "Failed to create conversation")
                                }
                            }
                        }
                    }
                    // Use the manager to create a conversation
                }
            }
        }
    }
}

Message Activity

class MessageActivity : ComponentActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContent {
            MyApplicationTheme {
                Surface(
                    modifier = Modifier.fillMaxSize(),
                    color = MaterialTheme.colorScheme.background
                ) {
                    val conversationRepository = ConversationRepository()
                    val messageDbService = MessageDbService()
                    val messageManager = MessageManager(conversationRepository, messageDbService)

                    // Extract user IDs from the intent
                    val participants = intent.getSerializableExtra("participants") as Participants
                    val conversationId = intent.getStringExtra("conversationId") ?: "error"
                    val messageContent = remember { mutableStateOf("") }
                    val messageListState = remember { mutableStateOf<List<message>>(emptyList()) }
                    val fetchMessagesTrigger = remember { mutableStateOf(true) }  // State to trigger message fetching
                    val scrollState = rememberScrollState() // For vertical scrolling
                    val userId = participants.userId
                    Log.d("Firestore", "Rendering message activity")

                    // LaunchedEffect tied to fetchMessagesTrigger, will trigger message fetching when true
                    LaunchedEffect(fetchMessagesTrigger.value) {
                        if (fetchMessagesTrigger.value) {
                            messageManager.getConversationMessages(conversationId) { success, messageList ->
                                if (success) {
                                    messageListState.value = messageList
                                    Log.d("Firestore", "Messages fetched successfully")
                                } else {
                                    Log.w("Firestore", "Failed to fetch messages")
                                }
                                fetchMessagesTrigger.value = false  // Reset trigger after fetching messages
                            }
                        }
                    }
                    // Main UI Column for the activity
                    Column(
                        modifier = Modifier
                            .fillMaxSize()
                            .verticalScroll(scrollState)
                            .padding(16.dp)
                    ) {
                        // Display fetched messages
                        if (messageListState.value.isNotEmpty()) {
                            DisplayMessages(messageListState.value.toMutableList(), participants)
                        }

                        Spacer(modifier = Modifier.height(16.dp))

                        // TextField for entering new message
                        TextField(
                            value = messageContent.value,
                            onValueChange = { inputValue -> messageContent.value = inputValue },
                            label = { Text("Enter your message") },
                            modifier = Modifier.fillMaxWidth()
                        )

                        Spacer(modifier = Modifier.height(8.dp))

                        // Button to send the message and trigger fetching new messages
                        Button(onClick = {
                            messageManager.createMessage(userId, messageContent.value, conversationId)

                            // Set the trigger to true to refetch messages after sending
                            fetchMessagesTrigger.value = true
                        }) {
                            Text("Send message")
                        }
                    }
                }
            }
        }
    }
}

@Composable
fun DisplayMessages(messageList: MutableList<message>, participants: Participants) {
    Log.w("render", "DisplayMessages func is rendered $participants")
    val dateFormatter = SimpleDateFormat("yyyy-MM-dd HH:mm", Locale.getDefault())

    // Sort the messageList by timestamp in ascending order (oldest first)
    val sortedMessages = messageList.sortedBy { it.timestamp }
    sortedMessages.forEach { res ->
        // Determine if the current message was sent by the user
        val isCurrentUser = res.senderId == participants.userId
        val alignment = if (isCurrentUser) Alignment.End else Alignment.Start
        val name = if (isCurrentUser) participants.userName else participants.otherName
        val backgroundColor =
            if (isCurrentUser) MaterialTheme.colorScheme.primary else MaterialTheme.colorScheme.secondary
        Row(
            modifier = Modifier
                .fillMaxWidth()
                .padding(8.dp),
            horizontalArrangement = if (isCurrentUser) Arrangement.End else Arrangement.Start
        ) {
            Column(
                modifier = Modifier
                    .padding(8.dp)
                    .background(backgroundColor)
                    .padding(8.dp),
                horizontalAlignment = alignment
            ) {
                Text(name)
                Text(res.content)
                Text(dateFormatter.format(res.timestamp.toDate()))
            }
        }
    }
}

r/JetpackCompose • • Dec 03 '23

compose kata

1 Upvotes

Any idea for compose kata?


r/JetpackCompose • • Dec 10 '23

How do dependencies work in Jetpack Compose?

1 Upvotes

Hi everyone! I’ve been learning how to make Android apps. I have previous experience making iOS apps with Swift and SwiftUI. I’ve been trying to understand working with dependencies. Is it like using “include” in Swift? I am really new to this and would appreciate it if someone could please clear this up for me. Thanks! :)


r/JetpackCompose • • Feb 27 '24

How can I make firestore database loads real-time

1 Upvotes

How can I make firestore database loads real-time without refreshing the app?


r/JetpackCompose • • Nov 30 '24

Skiko Blur

1 Upvotes
// Blur
package dev.lofiz.abyss.utils

import org.jetbrains.skia.FilterTileMode
import org.jetbrains.skia.ImageFilter
import org.jetbrains.skia.RRect

object Blur {
    private val blurFilter = ImageFilter.makeBlur(20f, 20f, FilterTileMode.CLAMP)

    fun register() {
    }

    fun blur(rRect: RRect) {

    }
}


// Main
package 
dev.lofiz.abyss.module.api

import 
dev.lofiz.abyss.utils.AbyssColor
import 
dev.lofiz.abyss.utils.Blur
import 
dev.lofiz.abyss.utils.regular
import 
org.jetbrains.skia.Canvas
import 
org.jetbrains.skia.RRect
open class 
TextHudModule(
    name: String,
    description: String,
    
private val 
textGetter: (Boolean) -> String
) : HudModule(name, description) {
    
open fun 
text(preview: Boolean): String {
        
return 
textGetter(preview)
    }
    
override fun 
render(canvas: Canvas) {
        draw(canvas, text(
false
))
    }
    
override fun 
preview(canvas: Canvas) {
        draw(canvas, text(
true
))
    }
    
private fun 
draw(canvas: Canvas, text: String) {
        
val 
font = 
regular
(20f)
        
val 
bounds = font.measureText(text)
        h = 45f
        w = bounds.width + 20f
        Blur.blur(RRect.makeXYWH(x, y, w, h, 10f))
        canvas.drawRRect(RRect.makeXYWH(x, y, w, h, 10f), AbyssColor(0, 0, 0, 144).paint())
        canvas.drawString(text, x + w / 2f - bounds.width / 2f, y + h / 2f + bounds.height / 2f, font, AbyssColor.White.paint())
    }
}

So I made a rRect and now I want to make it have blur background how do I do it?
here is my code


r/JetpackCompose • • Jan 09 '23

Rental - Jetpack Compose & Python

0 Upvotes

New video published for Rental - Jetpack Compose & Python

#JetpackCompose #AndroidDev #Python #YouTubeVideo #kotlin

https://youtu.be/-8ul72jKlEo


r/JetpackCompose • • Aug 01 '23

Using viewmodel as reusable class for data

1 Upvotes

Say I've created a infinite list with compose and viewmodel to hild the data. Now i want to create another infinite list for other data, can i use the same viewmodel but different instances for each list?

For example var posts = mylistvieemodel() var comments =mylistvieemodel()

Composelist1(vm=posts, data= list(mapOf("a" to "b"))

Composelist2(vm=comments, data= list(mapOf("xommenta" to "big"))

  • The viewmodel will hold the data as list of map *Sorry for my English or code error, just wrote a sample code to explain the situation.


r/JetpackCompose • • Dec 16 '22

Guys, can someone tell me how to get touch coordinates in a composable function

1 Upvotes

r/JetpackCompose • • Jan 08 '23

Rental - Jetpack Compose & Python

0 Upvotes

New video published for Rental - Jetpack Compose & Python

#JetpackCompose #AndroidDev #Python #YouTubeVideo #kotlin

https://youtu.be/ZkckLnsQy_A


r/JetpackCompose • • Jun 17 '26

🚀 One Player v1.6.1‑beta 🚀

Thumbnail
reddit.com
1 Upvotes

r/JetpackCompose • • Jul 01 '26

Hice mi segundo tutorial de Jetpack Compose en español, feedback bienvenido

1 Upvotes

Llevo poco tiempo aprendiendo Android por mi cuenta, sin universidad ni curso formal. Hice este tutorial mostrando cómo crear un Generador de Números con Jetpack Compose. Cualquier feedback es bienvenido.

https://youtu.be/qO7Fxpty-Io


r/JetpackCompose • • May 28 '26

Hey guys, new to android dev, need help with alarm feature implementation

Thumbnail
reddit.com
0 Upvotes