<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Thulasi Rajan P on Medium]]></title>
        <description><![CDATA[Stories by Thulasi Rajan P on Medium]]></description>
        <link>https://medium.com/@thulcgenius?source=rss-9723136c6347------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*z-3elnoMljZGzVGHxxR1Lw.jpeg</url>
            <title>Stories by Thulasi Rajan P on Medium</title>
            <link>https://medium.com/@thulcgenius?source=rss-9723136c6347------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 09:45:37 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@thulcgenius/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building a Pixel Perfect Light/Dark Theme Switch in Jetpack Compose]]></title>
            <link>https://thulcgenius.medium.com/building-a-pixel-perfect-light-dark-theme-switch-in-jetpack-compose-b22161b7177b?source=rss-9723136c6347------2</link>
            <guid isPermaLink="false">https://medium.com/p/b22161b7177b</guid>
            <dc:creator><![CDATA[Thulasi Rajan P]]></dc:creator>
            <pubDate>Mon, 12 Jan 2026 10:28:17 GMT</pubDate>
            <atom:updated>2026-01-14T02:51:40.829Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hO7GspZdBqRFsEAvG_AyJg.png" /><figcaption>Jetpack compose — custom switch</figcaption></figure><p>The default Switch component in Jetpack Compose is solid — it handles state, animations, and accessibility well. But sometimes design requirements push beyond what the built-in component offers. In my case, I needed to display text inside the switch itself showing “Light” or “Dark” mode. The default Switch? Doesn’t support that.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*x39pOQbb0XLfXVrEhk7VFQ.png" /><figcaption>Source: <a href="https://developer.android.com/static/develop/ui/compose/images/components/switches.png">https://developer.android.com/static/develop/ui/compose/images/components/switches.png</a></figcaption></figure><p>So I built a custom one. Here’s how.</p><h3>The Problem With Default</h3><p>Let me show you what I started with:</p><pre>@Composable<br>fun DefaultSwitchExample() {<br>    var isLightMode by remember { mutableStateOf(true) }<br><br>Switch(<br>        checked = isLightMode,<br>        onCheckedChange = { value -&gt;<br>            isLightMode = value<br>        },<br>        thumbContent = {<br>            Icon(<br>                painter = painterResource(R.drawable.ic_light_thumb),<br>                contentDescription = &quot;theme_switch&quot;,<br>                tint = Color.Unspecified,<br>            )<br>        },<br>        colors = SwitchDefaults.colors().copy(<br>            checkedTrackColor = Color.White,<br>            uncheckedTrackColor = Color.Black,<br>        )<br>    )<br>}</pre><p>This works — the switch toggles, the icon changes, colors respond to state. But here’s the limitation: there’s no room for text inside the track. The default component uses a specific layout structure (thumb + track) that doesn’t accommodate additional content like a label.</p><p>The design mockup showed something different: text visible inside the switch, positioned to show the current state. That meant I needed a different approach.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/186/1*WVah29pz1zPKujSyUsY_GA.png" /><figcaption>Source: Figma preview</figcaption></figure><h3>The Architecture: Thinking in “Equal States”</h3><p>Instead of fighting the default Switch’s structure, I reconceptualized the component. Rather than a “sliding thumb” mechanism, I modelled it as two equal states occupying the same space.</p><p>Here’s the key insight: both states (Light and Dark) would be the same width. The “movement” isn’t actually sliding — it’s a visual offset that creates the illusion of switching. This shift made the implementation cleaner and solved spacing issues I was running into.</p><p>The structure looks like this:</p><ul><li><strong>Parent Box</strong>: Contains everything, handles the click interaction</li><li><strong>Text Layer</strong>: Positioned absolutely, shows “Light” or “Dark” based on state</li><li><strong>Thumb Box</strong>: The circular element, positioned with offset to create the switch effect</li><li><strong>Icon</strong>: Inside the thumb, changes based on state</li></ul><h3>Building It: Step by Step</h3><p>Let’s start with the dimensions. I used smaller measurements than the standard 80.dp × 40.dp to match the design spec:</p><p>Now, here’s where it gets interesting. I’ll show you two versions: the instant toggle version, and then the animated version. Let me start with the basic version without animation:</p><h3>Version 1: Instant Toggle</h3><pre>private val customSwitchWidth = 66.dp<br>private val customSwitchHeight = 30.dp<br>private val customThumbSize = 24.dp<br><br>@Composable<br>fun CustomSwitchComponent() {<br>    var isLightMode by remember { mutableStateOf(true) }<br>    <br>    val thumbOffset = if (!isLightMode) <br>        (customSwitchWidth / 2) - (customThumbSize / 2)<br>    else <br>        -(customSwitchWidth / 2) + (customThumbSize / 2)<br>    val backgroundColor = if (!isLightMode) <br>        Color(0xFF121212) else Color(0xFFF2F2F2)<br>    val textColor = if (!isLightMode) <br>        Color.White else Color.Black<br>    Box(<br>        modifier = Modifier<br>            .width(customSwitchWidth)<br>            .height(customSwitchHeight)<br>            .clip(RoundedCornerShape(50))<br>            .background(backgroundColor)<br>            .clickable(<br>                role = Role.Switch,<br>                onClick = {<br>                    isLightMode = !isLightMode<br>                },<br>            ),<br>        contentAlignment = Alignment.Center,<br>    ) {<br>        Text(<br>            text = if (isLightMode) <br>                stringResource(R.string.dark) else stringResource(R.string.light),<br>            color = textColor,<br>            fontSize = 12.sp,<br>            fontWeight = FontWeight.Normal,<br>            modifier = Modifier.offset(x = if (!isLightMode) (-13).dp else 13.dp)<br>        )<br>         <br>        Box(<br>            modifier = Modifier<br>                .offset(x = if (!isLightMode) thumbOffset - 4.dp else thumbOffset + 4.dp)<br>                .size(customThumbSize)<br>                .clip(CircleShape)<br>                .background(<br>                    if (!isLightMode) Color(0xFF1E1E1E) else Color.White<br>                ),<br>            contentAlignment = Alignment.Center,<br>        ) {<br>            Icon(<br>                modifier = Modifier.size(customThumbSize),<br>                painter = painterResource(<br>                    if (!isLightMode) R.drawable.ic_dark_thumb<br>                    else R.drawable.ic_light_thumb<br>                ),<br>                contentDescription = stringResource(R.string.theme_switch),<br>                tint = Color.Unspecified,<br>            )<br>        }<br>    }<br>}</pre><figure><img alt="Jetpack compose custom switch implementation" src="https://cdn-images-1.medium.com/max/800/1*6BfWsFD2wIbuMv0BuUFTug.gif" /></figure><p>This version works perfectly — the toggle is instant and responsive. But if you want a more polished feel with smooth animations, here’s the enhanced version:</p><h3>Version 2: With Smooth Animation</h3><pre>@Composable<br>fun CustomSwitchComponent() {<br>    var isLightMode by remember { mutableStateOf(true) }<br><br>val thumbOffset by animateDpAsState(<br>        targetValue = if (!isLightMode)<br>            (customSwitchWidth / 2) - (customThumbSize / 2)<br>        else<br>            -(customSwitchWidth / 2) + (customThumbSize / 2),<br>        label = stringResource(R.string.custom_thumb_offset),<br>    )<br>    val backgroundColor by animateColorAsState(<br>        targetValue = if (!isLightMode) Color(0xFF121212) else Color(0xFFF2F2F2),<br>        label = stringResource(R.string.custom_switch_bg_colorr),<br>    )<br>    val textColor by animateColorAsState(<br>        targetValue = if (!isLightMode) Color.White else Color.Black,<br>        label = stringResource(R.string.custom_switch_text_colorr),<br>    )<br>    Box(<br>        modifier = Modifier<br>            .width(customSwitchWidth)<br>            .height(customSwitchHeight)<br>            .clip(RoundedCornerShape(50))<br>            .background(backgroundColor)<br>            .clickable(<br>                role = Role.Switch,<br>                onClick = {<br>                    isLightMode = !isLightMode<br>                },<br>            ),<br>        contentAlignment = Alignment.Center,<br>    ) {<br>        Text(<br>            text = if (isLightMode) <br>                stringResource(R.string.dark) else stringResource(R.string.light),<br>            color = textColor,<br>            fontSize = 12.sp,<br>            fontWeight = FontWeight.Normal,<br>            modifier = Modifier.offset(x = if (!isLightMode) (-13).dp else 13.dp)<br>        )<br>        <br>        Box(<br>            modifier = Modifier<br>                .offset(x = if (!isLightMode) thumbOffset - 4.dp else thumbOffset + 4.dp)<br>                .size(customThumbSize)<br>                .clip(CircleShape)<br>                .background(<br>                    if (!isLightMode) Color(0xFF1E1E1E) else Color.White<br>                ),<br>            contentAlignment = Alignment.Center,<br>        ) {<br>            Icon(<br>                modifier = Modifier.size(customThumbSize),<br>                painter = painterResource(<br>                    if (!isLightMode) R.drawable.ic_dark_thumb<br>                    else R.drawable.ic_light_thumb<br>                ),<br>                contentDescription = stringResource(R.string.theme_switch),<br>                tint = Color.Unspecified,<br>            )<br>        }<br>    }<br>}</pre><p>The difference is subtle but noticeable. The animated version uses animateDpAsState for the thumb offset and animateColorAsState for the background and text colors. This creates smooth transitions instead of instant changes.</p><figure><img alt="Jetpack Compose Custom Switch Implementation Animated" src="https://cdn-images-1.medium.com/max/800/1*YO6w9S314w_hAT5YGrAikg.gif" /></figure><h3>Understanding the Implementation</h3><p>Let me break down what’s happening here, because the calculations matter.</p><p><strong>The Dimension Calculations:</strong> I used 66.dp width and 24.dp thumb size to match a compact design spec. The thumb offset calculation works like this:</p><ul><li>When light mode is active: -(66/2) + (24/2) = -21.dp (left side)</li><li>When dark mode is active: (66/2) - (24/2) = 9.dp (right side)</li></ul><p>This creates equal spacing on both sides.</p><p><strong>The Text Offset:</strong> When isLightMode is true, we show &quot;Dark&quot; but position it to the right (13.dp). When false, we show &quot;Light&quot; and position it to the left (-13.dp). This creates the effect of text moving in and out as you toggle. The 13.dp value came from testing different offsets until the text felt balanced visually.</p><p><strong>The Thumb Offset Adjustment:</strong> The ±4.dp adjustment accounts for visual centering. Without it, the thumb looked slightly off-center. This is a common pattern in UI—sometimes the math doesn&#39;t match visual balance, so you fine-tune with small adjustments.</p><p><strong>Why Animation State Wrapping?</strong> In the animated version, wrapping the offset and color values in animateDpAsStateand animateColorAsState means Compose handles the animation frame-by-frame. You don&#39;t manually manage transitions; Compose smoothly interpolates between states. This keeps your code clean and lets Compose optimize the animation rendering.</p><p><strong>Why Not Animate the Text Offset?</strong> I intentionally left the text offset (±13.dp) without animation. It moves instantly while the thumb animates. This creates an intentional effect — the thumb glides smoothly while the text snaps in and out, emphasizing the state change.</p><h3>Adding Custom Animation Duration</h3><p>If you want to control animation speed, replace the animation calls with custom animationSpec:</p><pre>val thumbOffset by animateDpAsState(<br>    targetValue = if (!isLightMode)<br>        (customSwitchWidth / 2) - (customThumbSize / 2)<br>    else<br>        -(customSwitchWidth / 2) + (customThumbSize / 2),<br>    animationSpec = tween(durationMillis = 300),<br>    label = stringResource(R.string.custom_thumb_offset),<br>)</pre><p>The tween function lets you customize duration (in milliseconds). The default is 300ms, which feels smooth. Experiment with 200-400ms depending on your preference.</p><h3>Adding Haptic Feedback</h3><p>To make the toggle feel more responsive, add haptic feedback on click:</p><pre>val context = LocalContext.current<br><br>Box(<br>    modifier = Modifier<br>        .clickable(<br>            role = Role.Switch,<br>            onClick = {<br>                isLightMode = !isLightMode<br>                // Android system haptic feedback<br>                if (Build.VERSION.SDK_INT &gt;= Build.VERSION_CODES.R) {<br>                    context.vibrate(HapticFeedbackConstants.CONTEXT_CLICK)<br>                }<br>            },<br>        ),<br>    // ... rest of the code<br>)</pre><p>This gives users tactile confirmation that the toggle registered.</p><h3>What I Learned</h3><p>Building this component taught me a few things worth sharing:</p><p><strong>Think conceptually first.</strong> Before writing code, I modelled this as “equal states” rather than a “sliding mechanism.”</p><p><strong>Offset is powerful but requires precision.</strong> The offset modifier gives you fine-grained control, but you need to calculate positions carefully. Comments explaining those magic numbers (like the 13.dp) save future-you hours of confusion.</p><p><strong>Animation doesn’t require complexity.</strong> I almost used Animatable and manual animation state management. animateDpAsState is simpler and handles everything Compose needs.</p><p><strong>Default components have real trade-offs.</strong> The built-in Switch is excellent for standard use cases. When requirements deviate, custom building isn’t “better” — it’s just necessary. Know when to use each.</p><p><strong>Test across screen sizes.</strong> I built this for a specific width/height, but screens vary. Consider making dimensions parameters or theme values so you can reuse this in different contexts.</p><h3>Key Takeaways</h3><ul><li>Custom components solve real design constraints that built-in components can’t handle</li><li>Model your UI conceptually before implementing — it clarifies architecture decisions</li><li>The offset modifier combined with state gives you fine-grained control over positioning</li><li>Animation state wrapping (animateDpAsState, animateColorAsState) handles smooth transitions without boilerplate</li><li>Comments explaining calculations save you time and help teammates understand your reasoning</li><li>Test your assumptions — the 13.dp text offset came from visual testing, not math</li></ul><h3>Adding the Preview</h3><p>Here’s a complete preview you can use to see it in action:</p><pre>@Preview<br>@Composable<br>fun CustomSwitchPreview() {<br>    CustomswitchjetpackcomposeTheme {<br>        Box(<br>            modifier = Modifier.fillMaxSize(),<br>            contentAlignment = Alignment.Center,<br>        ) {<br>            CustomSwitchComponent()<br>        }<br>    }<br>}</pre><p>Run this preview in Android Studio to see the component in real-time. Click it to toggle between light and dark mode.</p><h3>Resources</h3><p><strong>GitHub Repository:</strong></p><p><a href="https://github.com/itsgeniuS/custom-switch-jetpack-compose">GitHub - itsgeniuS/custom-switch-jetpack-compose: Custom theme switch implementation in jetpack compose</a></p><p><strong>Useful Links to Reference:</strong></p><ul><li><a href="https://developer.android.com/jetpack/compose/modifiers">Jetpack Compose Modifier Documentation</a></li><li><a href="https://developer.android.com/jetpack/compose/animation">Understanding Compose Animations</a></li><li><a href="https://developer.android.com/develop/ui/compose/animation/value-based">animateDpAsState API Reference</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b22161b7177b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Building a Pixel Perfect Light/Dark Theme Switch in Jetpack Compose]]></title>
            <description><![CDATA[<div class="medium-feed-item"><p class="medium-feed-image"><a href="https://thulcgenius.medium.com/building-a-pixel-perfect-light-dark-theme-switch-in-jetpack-compose-9d364d68daad?source=rss-9723136c6347------2"><img src="https://cdn-images-1.medium.com/max/2240/1*hO7GspZdBqRFsEAvG_AyJg.png" width="2240"></a></p><p class="medium-feed-snippet">The default Switch component in Jetpack Compose is solid&#x200A;&#x2014;&#x200A;it handles state, animations, and accessibility well. But sometimes design&#x2026;</p><p class="medium-feed-link"><a href="https://thulcgenius.medium.com/building-a-pixel-perfect-light-dark-theme-switch-in-jetpack-compose-9d364d68daad?source=rss-9723136c6347------2">Continue reading on Medium »</a></p></div>]]></description>
            <link>https://thulcgenius.medium.com/building-a-pixel-perfect-light-dark-theme-switch-in-jetpack-compose-9d364d68daad?source=rss-9723136c6347------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d364d68daad</guid>
            <category><![CDATA[jetpack-compose-ui]]></category>
            <category><![CDATA[jetpack-compose]]></category>
            <category><![CDATA[compose-ui]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-ui]]></category>
            <dc:creator><![CDATA[Thulasi Rajan P]]></dc:creator>
            <pubDate>Mon, 12 Jan 2026 07:00:53 GMT</pubDate>
            <atom:updated>2026-01-12T07:00:53.950Z</atom:updated>
        </item>
        <item>
            <title><![CDATA[Publishing Android App as a Library in Jitpack.io using maven-publish]]></title>
            <link>https://thulcgenius.medium.com/publishing-android-app-as-a-library-in-jitpack-io-using-maven-publish-5145cae40fa5?source=rss-9723136c6347------2</link>
            <guid isPermaLink="false">https://medium.com/p/5145cae40fa5</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[android-app-development]]></category>
            <category><![CDATA[android-libraries]]></category>
            <category><![CDATA[dependency-management]]></category>
            <dc:creator><![CDATA[Thulasi Rajan P]]></dc:creator>
            <pubDate>Thu, 02 Jan 2025 07:07:20 GMT</pubDate>
            <atom:updated>2025-01-02T07:07:20.888Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*TRIa91rZG7yOAbum-oga9g.jpeg" /><figcaption>Android library publish jitpack.io using maven and consuming the library as dependency directly via Gradle.</figcaption></figure><p>In the last blog, I have given a walk-through of publishing android app with composable modules as a library and testing it using maven local. In case if you want, visit the below link to check the blog.</p><p><a href="https://medium.com/@thulcgenius/publishing-android-app-as-a-library-locally-using-maven-publish-3a5e4f618bbb">Publishing Android App as a Library Locally using maven-publish</a></p><p>Let’s begin with making the changes required for publishing the android module remotely. To achieve this we will be using jitpack.io, an open source platform where you can connect with github and directly create dependencies for android project. This will help us to package the boilerplate code we need to each project. We can publish this library as a package in jitpack.io and we can consume directly which will reduce our work or writing or copy/pasting the same piece of code again and again. So lets dive into it….</p><h4><strong>Step 1 : Connecting the Github account with jitpack.io</strong></h4><p>Click the following link to open the jitpack website : <a href="https://jitpack.io/"><strong><em>https://jitpack.io/</em></strong></a><strong><em>. </em></strong>Once you have opened the website, if you check the right top corner, you can see the sign in with Github option. You have to login with the same Github account where your android module exists. Basically jitpack.io offers two kinds of support, 3 private repo access and unlimited public repo access. I have created the project with public access for this example.</p><p>Once you have created account in jitpack.io you can see all the repositories that you have in Github account and it will list as below.,</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*iLBrxhQxcGjcnmw6LN4Hug.png" /><figcaption>jitpack.io dashboard</figcaption></figure><p>You can search for the library module on the search bar and it will display the respective releases, branches and commits on that repository.</p><h4><strong>Step 2: To add jitpack repository to build.gradle</strong></h4><p>Now in the consumer project we have to add the below dependencies</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVcI2-BIAcU8RLQ_ZXO21A.png" /><figcaption>Steps to setup consuming the library module on the consumer project.</figcaption></figure><p>in <em>settings.gradle.kts</em> file, add the following repository configuration</p><pre>dependencyResolutionManagement {<br>    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)<br>    repositories {<br>        google()<br>        mavenCentral()<br>//        mavenLocal() //for testing the library locally<br>        maven { url = URI(&quot;https://jitpack.io&quot;) } //to get the library from jitpack<br>    }<br>}</pre><p>The above code block will allow the gradle to look for the dependencies. In <em>build.gradle </em>file, add the following dependency</p><pre>dependencies {<br>    implementation(&quot;com.genius.jitpacklibrary_module:utils:0.0.1&quot;)<br>}</pre><p>Now <em>sync</em> the project. The library is added as an External Library to your consumer project and it’s ready for use.</p><h4>Task 3: Consuming the published library</h4><p>Now open the <em>MainActivity.kt</em>, here we will consume the hosted library and try to render the UI compose component.</p><pre>class MainActivity : ComponentActivity() {<br>    override fun onCreate(savedInstanceState: Bundle?) {<br>        super.onCreate(savedInstanceState)<br>        enableEdgeToEdge()<br>        setContent {<br>            val context = LocalContext.current<br><br>            JitpackLibraryConsumerTheme {<br>                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -&gt;<br>                    Box(<br>                        modifier = Modifier<br>                            .fillMaxSize()<br>                            .padding(innerPadding),<br>                        contentAlignment = Alignment.Center,<br>                        content = {<br>                            SmallText(<br>                                text = &quot;Small text displayed from library...&quot;,<br>                                modifier = Modifier<br>                                    .padding(innerPadding)<br>                                    .clickable {<br>                                        context.toastShort(&quot;Display toast from library...&quot;)<br>                                    }<br>                            )<br>                        }<br>                    )<br>                }<br>            }<br>        }<br>    }<br>}</pre><p>After adding the above code, hit <em>run</em>. You will see output something like below</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/1*QX2NukjGRj4zG3g1flV9pw.png" /><figcaption>App screenshot</figcaption></figure><p>That’s a wrap ! Now we are able to consume the library directly using dependencies.</p><p><strong>Thanks for reading! </strong>I hope you enjoyed it !! ✍️ Feel free to leave your thoughts in the comments section below.</p><p><em>Full source can be found below in github link :</em></p><ul><li><a href="https://github.com/itsgeniuS/JitpackLibrary-Module">GitHub - itsgeniuS/JitpackLibrary-Module: This project contains a sample library module, which will be converted to an android library and it is hosted on Jitpack.io and it will be used as a library on the consumer project.</a></li><li><a href="https://github.com/itsgeniuS/JitpackLibrary-Consumer">GitHub - itsgeniuS/JitpackLibrary-Consumer: This is a sample android project created to consume a self hosted android library from Jitpack.io</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5145cae40fa5" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publishing Android App as a Library Locally using maven-publish]]></title>
            <link>https://thulcgenius.medium.com/publishing-android-app-as-a-library-locally-using-maven-publish-3a5e4f618bbb?source=rss-9723136c6347------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a5e4f618bbb</guid>
            <category><![CDATA[android-compose]]></category>
            <category><![CDATA[compose-library-android]]></category>
            <category><![CDATA[android-jitpack-library]]></category>
            <category><![CDATA[compose-ui]]></category>
            <category><![CDATA[android-libraries]]></category>
            <dc:creator><![CDATA[Thulasi Rajan P]]></dc:creator>
            <pubDate>Mon, 12 Aug 2024 14:16:18 GMT</pubDate>
            <atom:updated>2024-08-12T14:21:08.124Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IyDMyPInoFN_c5qmea1dJQ.jpeg" /><figcaption>Android library publish locally on mac and windows.</figcaption></figure><p>Recently, I published a library for one of my projects., and me and my team came up with a approach for creating a separate module as library so that we can reuse the module in the upcoming projects.</p><p>In this project, I took myself the task to do the groundwork for publishing that particular module as a library. In this blog, I will share my learnings on publishing android module as a library using jitpack and maven.</p><p><strong><em>For</em></strong> simpler understanding, I have created two projects One is Library module and another one is consumer module, where the library module has certain components of compose and we are planning to re-use those components in the Consumer project. Let’s get started !</p><h3><strong>Task 1:</strong> Setting up to publish the library locally</h3><p><strong><em>Once</em></strong> you have created an an android project named as library module, we have to add the below plugin to support publishing the project as a library to jitpack.io and it will offer two types of publishing the library.</p><p>Step 1 : To publish the maven library locally to test it using mavenLocal()</p><p>Step 2 : To finally publish the library on jitpack.io and we can use it as a dependency in another project.</p><ol><li>Add the below plugin to the app level build.gradle.kts</li></ol><pre>plugins {<br> //...rest of other plugins<br> //...<br> id(&quot;maven-publish&quot;) //add this publish support plugin<br>}</pre><p>5. Now in the same gradle file add the below configuration</p><pre>configure&lt;PublishingExtension&gt; {<br>    publications.create&lt;MavenPublication&gt;(ConfigData.PublishingData.ARTIFACT_ID) {<br><br>       groupId = ConfigData.PublishingData.GROUP_ID<br>       artifactId = ConfigData.PublishingData.ARTIFACT_ID<br>       version = ConfigData.PublishingData.RELEASE_VERSION<br>       artifact(ConfigData.PublishingData.ARTIFACT_PATH)<br><br>       pom {<br>          name = ConfigData.PublicationData.PUBLISHER_NAME<br>          description = ConfigData.PublicationData.PUBLISHER_DESCRIPTION<br>          url = ConfigData.PublicationData.PUBLISHER_URL<br><br>          developers {<br>             name = ConfigData.PublisherData.AUTHOR_NAME<br>             description = ConfigData.PublisherData.AUTHOR_EMAIL<br>             organization {<br>                url = ConfigData.PublisherData.AUTHOR_PORTFOLIO<br>             }<br>          }<br>       }<br>    }<br>}</pre><p>6. I am using buildSrc to manage the dependencies and versions as below</p><pre>/**<br> * Created by Thulasi Rajan P on 28/07/24.<br> */<br>object ConfigData {<br><br> /**<br>  * Library publishing info for jitpack.io<br>  * */<br> interface PublishingData {<br>  companion object {<br>   const val GROUP_ID = &quot;com.genius.jitpacklibrary_module&quot;<br>   const val ARTIFACT_ID = &quot;utils&quot;<br>   const val ARTIFACT_NAME = &quot;utils-release.aar&quot;<br>   const val ARTIFACT_PATH = &quot;../utils/build/outputs/aar/$ARTIFACT_NAME&quot;<br>   const val RELEASE_VERSION = &quot;0.0.1&quot;<br>  }<br> }<br><br> /**<br>  * Library publication info<br>  * */<br> interface PublicationData {<br>  companion object {<br>   const val PUBLISHER_NAME = &quot;Thulasi rajan P&quot;<br>   const val PUBLISHER_URL = &quot;https://itsgenius.github.io&quot;<br>   const val PUBLISHER_DESCRIPTION = &quot;Senior Android Developer&quot;<br>  }<br> }<br><br> /**<br>  * Library author information<br>  * */<br> interface PublisherData {<br>  companion object {<br>   const val AUTHOR_NAME = &quot;Thulasi Rajan P&quot;<br>   const val AUTHOR_EMAIL = &quot;thulcgenius@gmail.com&quot;<br>   const val AUTHOR_PORTFOLIO = &quot;https://itsgenius.github.io/&quot;<br>  }<br> }<br>}</pre><p>Now we have completed the required things to publish the library locally.</p><h3>Task 2: Publishing the library locally</h3><p>Now open the terminal in Android Studio and type the following commands, I’m using mac so i used the below commands to run the gradle tasks.</p><p>To generate the aar file of the library we have to use the following task:</p><pre>./gradlew clean assembleDebug</pre><p>Once the task runs successfully, then to publish the maven in your local machine you have to run the below task</p><pre>./gradlew publishToMavenLocal</pre><p>This command will publish the library in your local system inside the .m2 folder. You can check that folder to see your package name, and you can also find your aar file published with version level packages.</p><h3>Task 3: Consuming the locally published library by another project</h3><p>Now we have to create a new android project named as Consumer, just create a simple activity with compose and we can integrate the locally published library in this project.</p><p>Once the project is created and build sync is completed, open the <em>settings.gradle.kts </em>inside the repositories block declare the following code to access the maven hosted library inside this project.</p><pre>dependencyResolutionManagement {<br>    repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)<br>    repositories {<br>        google()<br>        mavenCentral()<br><br>        mavenLocal() //for testing the library locally<br>    }<br>}</pre><p>Once you add the local library dependency, the gradle need to sync now so that it will get access to the .m2 folder where the library is hosted.</p><p>Now open your app level<em> build.gradle.kts</em> file and add the below dependency to access the library locally.</p><pre>dependencies {<br>    //other libraries declared here<br>    implementation(&quot;com.genius.jitpacklibrary_module:utils:0.0.1&quot;)<br>}</pre><p>Once you have declared the library now you can sync the gradle again to accomodate the changes from the locally hosted library also. The gradle will try to fetch the library in the repositories what ever we have given access to it. <em>mavenLocal()</em>. will help us to synchronise the library code with the app code. Now Once the sync is successfully completed, you can open the <em>MainActivity</em> and try to access the library <em>composable</em>.</p><pre>setContent {<br>            val context = LocalContext.current<br><br>            JitpackLibraryConsumerTheme {<br>                Scaffold(modifier = Modifier.fillMaxSize()) { innerPadding -&gt;<br>                    Box(<br>                        modifier = Modifier<br>                            .fillMaxSize()<br>                            .padding(innerPadding),<br>                        contentAlignment = Alignment.Center,<br>                        content = {<br>                            SmallText(<br>                                text = &quot;Small text displayed from library...&quot;,<br>                                modifier = Modifier<br>                                    .padding(innerPadding)<br>                                    .clickable {<br>                                        context.toastShort(&quot;Display toast from library...&quot;)<br>                                    }<br>                            )<br>                        }<br>                    )<br>                }<br>            }<br>        }</pre><p>Now update your setContent block with the above piece of code, and run the app. Your composable will also display from the toast when clicked…</p><p>Your output will be something like below…</p><figure><img alt="Composable module as library in android app …" src="https://cdn-images-1.medium.com/max/1024/1*22Rz7jF4d3CIY2s_DQCezw.png" /></figure><p>Hurray !!! Now we have our composable which is inside a module and we are using it as a library. Similar to this we can implement our own composables as a library and we can access it locally.</p><p>That’s a wrap ! In next blog, I will share my experiences while publishing it as a library remotely on jitpack.io <br>I hope you enjoy it !! ✍️</p><p><em>Full source can be found below in github link :</em></p><ul><li><a href="https://github.com/itsgeniuS/JitpackLibrary-Consumer">GitHub - itsgeniuS/JitpackLibrary-Consumer: This is a sample android project created to consume a self hosted android library from Jitpack.io</a></li><li><a href="https://github.com/itsgeniuS/JitpackLibrary-Module">GitHub - itsgeniuS/JitpackLibrary-Module: This project contains a sample library module, which will be converted to an android library and it is hosted on Jitpack.io and it will be used as a library on the consumer project.</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a5e4f618bbb" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Mastering Navigation in Android Compose UI — Integrating Bottom Navigation and Non-Bottom Menu…]]></title>
            <link>https://thulcgenius.medium.com/mastering-navigation-in-android-compose-ui-integrating-bottom-navigation-and-non-bottom-menu-c22a115f39f1?source=rss-9723136c6347------2</link>
            <guid isPermaLink="false">https://medium.com/p/c22a115f39f1</guid>
            <category><![CDATA[compose-multiplatform]]></category>
            <category><![CDATA[android]]></category>
            <category><![CDATA[compose-navigation]]></category>
            <category><![CDATA[compose-bottom-navigation]]></category>
            <category><![CDATA[bottomnavigationview]]></category>
            <dc:creator><![CDATA[Thulasi Rajan P]]></dc:creator>
            <pubDate>Sat, 25 May 2024 12:57:26 GMT</pubDate>
            <atom:updated>2024-05-25T12:57:26.135Z</atom:updated>
            <content:encoded><![CDATA[<h3><strong>Mastering Navigation in Android Compose UI — Integrating Bottom Navigation and Non-Bottom Menu Screens</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*rgQUewvhLR98TU27" /><figcaption>Navigation flow of the app with and without bottom menu — in single navigation graph.</figcaption></figure><h3>Problem statement :-</h3><p>I have been learning compose since last few months, and in one of the recent projects there was a UI design with the above mentioned flow (i.e) with and without bottom menus. And I wanted to implement it with Single Navigation Graph as the app has so minimal features and there is no specific requirement to use nested graph. (personally I thought…). So Let’s dive into the detailed steps you’ll need to follow in case you need to implement something like this.</p><h3>Project setup :-</h3><p>First create an empty Compose project in Android Studio. And then in the <strong><em>build.gradle</em></strong> file add the below dependencies inside the dependencies block</p><pre>implementation(&quot;androidx.compose.material:material:1.6.7&quot;)<br>implementation(&quot;androidx.navigation:navigation-compose:2.7.7&quot;)</pre><h3>Creating the screens :-</h3><p>Create a Kotlin file named as <strong><em>AppScreens.kt </em></strong><em>, </em>In this file let’s create a sealed class to declare the Screens.</p><pre>sealed class AppScreens(<br>   val route: String,<br>   val label: String,<br>   val drawable: ImageVector? = null<br>) {<br>   //direct screens<br>   data object Splash : AppScreens(route = &quot;splash&quot;, label = &quot;SplashScreen&quot;)<br>   data object Notifications : AppScreens(route = &quot;notifications&quot;, label = &quot;Notifications&quot;)<br>   data object HomeToNextScreen : AppScreens(route = &quot;homeToNext&quot;, label = &quot;HomeToNextScreen&quot;)<br><br>   //bottom menu screens<br>   data object Home : AppScreens(<br>       route = &quot;home&quot;,<br>       label = &quot;Home&quot;,<br>       drawable = Icons.Default.Home<br>   )<br><br>   data object Orders : AppScreens(<br>       route = &quot;orders&quot;,<br>       label = &quot;Orders&quot;,<br>       drawable = Icons.Default.List<br>   )<br><br>   data object Profile : AppScreens(<br>       route = &quot;profile&quot;,<br>       label = &quot;Profile&quot;,<br>       drawable = Icons.Default.AccountCircle<br>   )<br>}<br><br>val bottomMenuScreens = listOf(<br>   AppScreens.Home.route,<br>   AppScreens.Profile.route,<br>   AppScreens.Orders.route<br>)</pre><p>In the above code, I have declared the screens that we will be using.</p><h3>Creating Navigation Graph:</h3><p>Lets create a navigation graph, Before that I wanted to say that the bottom menu is a part of Activity always if we need to make a single navigation and also I found that this approach works well, If you have any other ideas let me know in the comments.</p><pre>@Composable<br>fun BuildAppNavGraph() {<br>   val navController = rememberNavController()<br><br>   val navBackStackEntry by navController.currentBackStackEntryAsState()<br>   val currentRoute = navBackStackEntry?.destination?.route<br>   val canShowBottomBar = currentRoute in bottomMenuScreens<br><br>   Scaffold(<br>       bottomBar = {<br>           if (canShowBottomBar) {<br>               BuildBottomNavigationBar(navController, currentRoute)<br>           }<br>       },<br>       content = { paddingValues -&gt;<br>           Box(<br>               modifier = Modifier.padding(<br>                   bottom = paddingValues.calculateBottomPadding()<br>               )<br>           ) {<br>               NavHost(<br>                   navController = navController,<br>                   startDestination = AppScreens.Splash.route<br>               ) {<br>                   composable(route = AppScreens.Splash.route) {<br>                       SplashScreen(navController)<br>                   }<br>                   composable(route = AppScreens.Home.route) {<br>                       HomeScreen(navController)<br>                   }<br>                   composable(route = AppScreens.Orders.route) {<br>                       OrdersScreen(navController)<br>                   }<br>                   composable(route = AppScreens.Profile.route) {<br>                       ProfileScreen(navController)<br>                   }<br>                   composable(route = AppScreens.Notifications.route) {<br>                       NotificationScreen(navController)<br>                   }<br>                   composable(route = AppScreens.HomeToNextScreen.route) {<br>                       HomeToNextScreen(navController)<br>                   }<br>               }<br>           }<br>       }<br>   )<br>}</pre><p>This navigation graph, will be directly fed to the content of the activity as below.</p><pre>class MainActivity : ComponentActivity() {<br>   override fun onCreate(savedInstanceState: Bundle?) {<br>       super.onCreate(savedInstanceState)<br>       enableEdgeToEdge()<br>       setContent {<br>           Compose_single_graph_navigationTheme {<br>               BuildAppNavGraph()<br>           }<br>       }<br>   }<br>}</pre><p>Now let’s construct the bottom menu, I have created a composable for that and that looks like below.,</p><pre>@Composable<br>fun BuildBottomNavigationBar(<br>   navController: NavHostController,<br>   currentRoute: String?<br>) {<br>   val bottomMenus = listOf(<br>       AppScreens.Home,<br>       AppScreens.Orders,<br>       AppScreens.Profile<br>   )<br><br>   BottomAppBar(<br>       modifier = Modifier.fillMaxWidth(),<br>       content = {<br>           bottomMenus.forEach { item -&gt;<br>               BottomNavigationItem(<br>                   selected = currentRoute == item.route,<br>                   onClick = {<br>                       navController.navigate(item.route) {<br>                           popUpTo(navController.graph.startDestinationId)<br>                           launchSingleTop = true<br>                       }<br>                   },<br>                   icon = { Icon(imageVector = item.drawable!!, contentDescription = item.label) },<br>                   label = { Text(item.label) },<br>                   selectedContentColor = Color.Black,<br>                   unselectedContentColor = Color.Gray,<br>               )<br>           }<br>       }<br>   )<br>}</pre><p>FYI, I’m including the git repo here so that you can see the code, Git link:</p><p><a href="https://github.com/itsgeniuS/compose_single_graph_navigation"><strong>GitHub — itsgeniuS/compose_single_graph_navigation: Compose Android App with bottom menu and other…</strong></a></p><p><a href="https://github.com/itsgeniuS/compose_single_graph_navigation"><em>Compose Android App with bottom menu and other single screens with single navigation graph. …</em>github.com</a></p><h3>Navigation implementation :</h3><ol><li><strong>Direct Navigation to screen</strong> : For the screens without bottom menu we can directly call like below,</li></ol><pre>Button(<br>   onClick = {<br>        navController.navigate(AppScreens.Home.route)<br>   },<br>   modifier = Modifier.padding(top = 10.dp)<br>) {<br>   Text(text = &quot;Open home&quot;)<br>}</pre><p>2. <strong>Bottom Navigation item to screen</strong> : For the bottom menus, we will pop the previous screens and we will launch the new screen inside the same container as below,</p><pre>BottomNavigationItem(<br>  selected = currentRoute == item.route,<br>  onClick = {<br>      navController.navigate(item.route) {<br>      popUpTo(navController.graph.startDestinationId)<br>      launchSingleTop = true<br>    }<br> },<br> icon = { Icon(imageVector = item.drawable!!, contentDescription = item.label) },<br> label = { Text(item.label) },<br> selectedContentColor = Color.Black,<br> unselectedContentColor = Color.Gray,<br>)</pre><h3>Conclusion:</h3><p>Implementing single navigation graph with this approach has been never easy as far as I felt. By following this guide, you should be well-equipped to add a Bottom Navigation Bar to your next Jetpack Compose project.</p><p>Happy Coding ✌️ I Hope this helps you in any part of the work, Thanks guys. See you later…</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c22a115f39f1" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>