<?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 Codeangi on Medium]]></title>
        <description><![CDATA[Stories by Codeangi on Medium]]></description>
        <link>https://medium.com/@codeangi?source=rss-11afc146ad7f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*RWQsvybXTopDARl4B5WK5A.jpeg</url>
            <title>Stories by Codeangi on Medium</title>
            <link>https://medium.com/@codeangi?source=rss-11afc146ad7f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 03:00:43 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@codeangi/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[Meet “YCharts”: an Opensource Jetpack Compose chart library.]]></title>
            <link>https://medium.com/ymedialabs-innovation/meet-ycharts-an-opensource-jetpack-compose-chart-library-2568aeac19fb?source=rss-11afc146ad7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/2568aeac19fb</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[charts-and-graphs]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[ios]]></category>
            <dc:creator><![CDATA[Codeangi]]></dc:creator>
            <pubDate>Thu, 13 Jul 2023 06:29:03 GMT</pubDate>
            <atom:updated>2023-09-26T07:43:42.136Z</atom:updated>
            <content:encoded><![CDATA[<h3>Meet “Y-Charts”: an Opensource Jetpack Compose chart library.</h3><p><a href="https://github.com/yml-org/YCharts">GitHub - yml-org/YCharts: YCharts is a graph library for Android.</a></p><p><strong>Y-Charts </strong>is a <strong>Jetpack Compose-based</strong> charts/graphs library that enables developers to easily integrate various types of charts/graphs into their existing UI to visually represent statistical data. Jetpack Compose is Android’s recommended modern toolkit for building native UI. Y-Charts leverages on powerful features of Jetpack Compose to deliver accurate and accessible results for users, and many reusable components allow it to be concise and lightweight also enabling developers to customize and add new charts with ease.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/430/1*5-iU0VMI98_JnqM-3a3OgA.gif" /><figcaption>Y-Charts Sample in action.</figcaption></figure><h4>Adding Y-charts to your project.</h4><p>You can add the library via Maven:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f3feb939f36855b0cec632a08a6c6fa8/href">https://medium.com/media/f3feb939f36855b0cec632a08a6c6fa8/href</a></iframe><h3>Charts in Y-Charts:</h3><h4><strong>1. </strong>Cartesian Charts:</h4><p>Cartesian charts, also known as coordinate charts or xy-charts, utilize a rectangular coordinate system with two perpendicular axes: the x-axis (horizontal) and the y-axis (vertical). These charts are particularly effective for displaying quantitative data and relationships between variables.</p><blockquote><strong>AxisData</strong>: The AxisData model supplied to each chart item controls the behavior and appearance of X and Y axis labels, user can opt for default behavior via the builder and can customize according to their needs.</blockquote><ul><li><strong>Bar Charts: </strong>Bar charts use rectangular bars to represent data, where the length or height of each bar corresponds to its value.<br>Y-Charts provides many customization including the orientation of the bar chart to achieve a horizontal-scroll behavior, along with grouping and stacking of bars. This enables users to visualize different types of bar charts with very few code changes. <strong>BarchartData and GroupBarChartData </strong>enable users to customize this behavior, additionally, users can change the appearance of the bars by using the <strong>BarStyle </strong>property. <strong>BarData </strong>represents the data for each bar shown in the chart. Following snippet shows the<strong> BarchartData </strong>declaration and usage of Barchart Composable<strong>.</strong></li></ul><pre>data class BarChartData(<br>    val chartData: List&lt;BarData&gt;,<br>    val xAxisData: AxisData = AxisData.Builder().build(),<br>    val yAxisData: AxisData = AxisData.Builder().build(),<br>    val backgroundColor: Color = Color.White,<br>    val horizontalExtraSpace: Dp = 0.dp,<br>    val barStyle: BarStyle = BarStyle(),<br>    val paddingEnd: Dp = 10.dp,<br>    val paddingTop: Dp = 0.dp,<br>    val tapPadding: Dp = 10.dp,<br>    val showYAxis: Boolean = true,<br>    val showXAxis: Boolean = true,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig(),<br>    val barChartType: BarChartType = BarChartType.VERTICAL,<br>    val drawBar: (DrawScope, BarData, Offset, Float, BarChartType, BarStyle) -&gt; Unit = { drawScope, barChartData, drawOffset, height, barChartType, barStyle -&gt;<br>        //default implementation<br>        drawBarGraph(drawScope, barChartData, drawOffset, height, barChartType, barStyle)<br>    }<br>)<br><br>//usage <br>   <br>BarChart(modifier = Modifier.height(350.dp), barChartData = barChartData)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*wvBFarXvW4DmhPc4Y26pKQ.gif" /><figcaption>Various types/customizations of Barchart in Y-Charts Library in action</figcaption></figure><ul><li><strong>Line Charts</strong>: Line charts, also known as line graphs, are used to depict the relationship between two variables over a continuous interval or time. LineChartData Model provided in Y-Charts enables customization such as line color, line appearance etc. Line chart in Y-charts also supports multiple line charts to be drawn in a single graph.</li></ul><pre>data class LineChartData(<br>    val linePlotData: LinePlotData,<br>    val xAxisData: AxisData = AxisData.Builder().build(),<br>    val yAxisData: AxisData = AxisData.Builder().build(),<br>    val isZoomAllowed: Boolean = true,<br>    val paddingTop: Dp = 30.dp,<br>    val bottomPadding: Dp = 10.dp,<br>    val paddingRight: Dp = 10.dp,<br>    val containerPaddingEnd: Dp = 15.dp,<br>    val backgroundColor: Color = Color.White,<br>    val gridLines: GridLines? = null,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig()<br>)<br><br>//usage<br>    LineChart(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .height(300.dp),<br>        lineChartData = data<br>    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*kayQW5IFlZJ-_YJGxbjfFQ.gif" /><figcaption>Linechart examples in the sample app.</figcaption></figure><ul><li><strong>Wave Charts</strong>: Wave charts, also referred to as waveform charts or waveform displays, are specialized visualizations used primarily in the field of signal processing and electronics. WaveChartData is the model used to customize Wave chart appearance and behavior, user can create a sine-wave chart and amplitude wave chart by using necessary values.</li></ul><pre>data class WaveChartData(<br>    val wavePlotData: WavePlotData,<br>    val xAxisData: AxisData = AxisData.Builder().build(),<br>    val yAxisData: AxisData = AxisData.Builder().build(),<br>    val isZoomAllowed: Boolean = true,<br>    val paddingTop: Dp = 30.dp,<br>    val bottomPadding: Dp = 10.dp,<br>    val paddingRight: Dp = 10.dp,<br>    val containerPaddingEnd: Dp = 15.dp,<br>    val backgroundColor: Color = Color.White,<br>    val gridLines: GridLines? = null,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig()<br>)<br><br>//usage<br>    WaveChart(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .height(300.dp),<br>        waveChartData = data<br>    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*Xgw2R0yHSKEVpwLmqaP6xA.gif" /><figcaption>wave charts in sample app</figcaption></figure><ul><li><strong>Bubble Charts</strong>: Bubble charts are a variation of the scatter plot, where the data points are represented as bubbles or circles instead of simple dots. The bubbles’ size represents the value of a third variable, in addition to the x-axis and y-axis variables. BubbleChartData contains a list of bubbles, where each bubble is represented by Bubble model, Users can also set the maximum bubble radius to keep the bubble radius relative to supplied density value for each bubble.</li></ul><pre>data class BubbleChartData(<br>    val bubbles: List&lt;Bubble&gt;,<br>    val maximumBubbleRadius:Float = 100f,<br>    val xAxisData: AxisData = AxisData.Builder().build(),<br>    val yAxisData: AxisData = AxisData.Builder().build(),<br>    val isZoomAllowed: Boolean = true,<br>    val paddingTop: Dp = 30.dp,<br>    val bottomPadding: Dp = 10.dp,<br>    val paddingRight: Dp = 10.dp,<br>    val containerPaddingEnd: Dp = 15.dp,<br>    val backgroundColor: Color = Color.White,<br>    val gridLines: GridLines? = null,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig()<br>)<br><br>//usage<br>  BubbleChart(<br>        modifier = Modifier<br>            .fillMaxWidth()<br>            .height(500.dp),<br>        bubbleChartData = data<br>    )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*vnro5YlKa8PWfxXkmeGB4Q.gif" /><figcaption>Bubblechart in the sample app.</figcaption></figure><ul><li><strong>Combined Charts:</strong> Combined charts, also known as combo charts, are visualizations that combine multiple chart types within a single graph. They allow for the simultaneous representation of different types of data or the comparison of multiple variables. In Y-Charts users can use CombinedChartData to implement Linechart and a Barchart on a single graph, where BarPlotData and LinePlotData determines the data set of Bar chart and Line chart respectively.</li></ul><pre>data class CombinedChartData(<br>    val combinedPlotDataList: List&lt;PlotData&gt;,<br>    val xAxisData: AxisData = AxisData.Builder().build(),<br>    val yAxisData: AxisData = AxisData.Builder().build(),<br>    val paddingTop: Dp = 30.dp,<br>    val bottomPadding: Dp = 10.dp,<br>    val paddingEnd: Dp = 10.dp,<br>    val horizontalExtraSpace: Dp = 10.dp,<br>    val containerPaddingEnd: Dp = 15.dp,<br>    val backgroundColor: Color = Color.White,<br>    val tapPadding: Dp = 10.dp,<br>    val isZoomAllowed: Boolean = true,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig()<br>)<br>//usage<br> CombinedChart(<br>            modifier = Modifier<br>                .height(400.dp),<br>            combinedChartData = combinedChartData<br>        )</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/272/1*Xq3lZK6CBDCoR-qSXD-seQ.gif" /><figcaption>Combined charts in Y charts</figcaption></figure><h4><strong>2. </strong>Polar Charts:</h4><p>Polar charts, also known as radial charts, utilize a polar coordinate system with a central point and radial axes. These charts are effective in representing cyclical or angular data, as well as comparing multiple variables around a central point.</p><ul><li><strong>Pie Charts</strong>: Pie charts are circular graphs divided into slices that represent different categories or proportions of a whole. Each slice’s size corresponds to the proportion it represents relative to the total. <br>Users can implement Pie chart using PieChartData in Y-Charts, and can customize parameters such as slice portion, slice label and slice color.<br>PieChartConfig is used to control the overall behavior and to customize labels being shown to represent the slices.</li></ul><pre> PieChartData(val slices: List&lt;Slice&gt;, override val plotType: PlotType)<br>//configuring piechart<br>data class PieChartConfig(<br>    val startAngle: Float = DEFAULT_START_ANGLE,<br>    val showSliceLabels: Boolean = true,<br>    val sliceLabelTextSize: TextUnit = DEFAULT_SLICE_LABEL_TEXT_SIZE.sp,<br>    val sliceLabelTextColor: Color = Color.White,<br>    val sliceLabelTypeface: Typeface = Typeface.DEFAULT,<br>    val isAnimationEnable: Boolean = false,<br>    @IntRange(from = 1) val animationDuration: Int = 500,<br>    val strokeWidth: Float = DEFAULT_STROKE_WIDTH,<br>    val labelFontSize: TextUnit = 24.sp,<br>    val labelTypeface: Typeface = Typeface.DEFAULT,<br>    val labelVisible: Boolean = false,<br>    val labelType: LabelType = LabelType.PERCENTAGE,<br>    val labelColor: Color = Color.White,<br>    val labelColorType: LabelColorType = LabelColorType.SPECIFIED_COLOR,<br>    val backgroundColor: Color = Color.White,<br>    val activeSliceAlpha: Float = .8f,<br>    val inActiveSliceAlpha: Float = 1f,<br>    val isEllipsizeEnabled: Boolean = false,<br>    val sliceMinTextWidthToEllipsize: Dp = 80.dp,<br>    val sliceLabelEllipsizeAt: TextUtils.TruncateAt = TextUtils.TruncateAt.END,<br>    val chartPadding: Int = DEFAULT_PADDING,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig(<br>        chartDescription = PieChartConstants.DESCRIPTION<br>    ),<br>    val isSumVisible: Boolean = false,<br>    val sumUnit: String = &quot;&quot;,<br>    val isClickOnSliceEnabled: Boolean = true<br>)<br><br>//usage<br>   PieChart(<br>                            modifier = Modifier<br>                                .fillMaxWidth()<br>                                .height(500.dp),<br>                            pieChartData,<br>                            pieChartConfig<br>                        ) { slice -&gt;<br>            }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/263/1*lmvKhYU8rO4b5YUE7SmwNQ.gif" /><figcaption>piecharts in Y charts</figcaption></figure><ul><li><strong>Donut Charts:</strong> Donut charts are similar to pie charts in terms of their purpose and usage. However, donut charts have a hole in the center. Similar to Pie Charts, users can customize overall appearance of the chart using the PieChartConfig and each slice can be customized using the Slice objects supplied as a list to PieChartData.</li></ul><pre>PieChartData(val slices: List&lt;Slice&gt;, override val plotType: PlotType)<br>//configuring piechart<br>data class PieChartConfig(<br>    val startAngle: Float = DEFAULT_START_ANGLE,<br>    val showSliceLabels: Boolean = true,<br>    val sliceLabelTextSize: TextUnit = DEFAULT_SLICE_LABEL_TEXT_SIZE.sp,<br>    val sliceLabelTextColor: Color = Color.White,<br>    val sliceLabelTypeface: Typeface = Typeface.DEFAULT,<br>    val isAnimationEnable: Boolean = false,<br>    @IntRange(from = 1) val animationDuration: Int = 500,<br>    val strokeWidth: Float = DEFAULT_STROKE_WIDTH,<br>    val labelFontSize: TextUnit = 24.sp,<br>    val labelTypeface: Typeface = Typeface.DEFAULT,<br>    val labelVisible: Boolean = false,<br>    val labelType: LabelType = LabelType.PERCENTAGE,<br>    val labelColor: Color = Color.White,<br>    val labelColorType: LabelColorType = LabelColorType.SPECIFIED_COLOR,<br>    val backgroundColor: Color = Color.White,<br>    val activeSliceAlpha: Float = .8f,<br>    val inActiveSliceAlpha: Float = 1f,<br>    val isEllipsizeEnabled: Boolean = false,<br>    val sliceMinTextWidthToEllipsize: Dp = 80.dp,<br>    val sliceLabelEllipsizeAt: TextUtils.TruncateAt = TextUtils.TruncateAt.END,<br>    val chartPadding: Int = DEFAULT_PADDING,<br>    val accessibilityConfig: AccessibilityConfig = AccessibilityConfig(<br>        chartDescription = PieChartConstants.DESCRIPTION<br>    ),<br>    val isSumVisible: Boolean = false,<br>    val sumUnit: String = &quot;&quot;,<br>    val isClickOnSliceEnabled: Boolean = true<br>)<br><br>    DonutPieChart(<br>                    modifier = Modifier<br>                        .width(100.dp)<br>                        .height(100.dp),<br>                    data,<br>                    firstPieChartConfig<br>                ) { slice -&gt;}</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/265/1*xsXWS3q61nL93D5TTvtDyQ.gif" /><figcaption>Donut-charts demo in Y-Charts sample app</figcaption></figure><h3>Developing/Customizing Y-Charts.</h3><h4>Reusable Components of Y-Charts.</h4><p>In cartesian charts or XY-Charts, the charts are drawn based on the coordinates represented by X and Y. In Y-Charts, we have a reusable <strong>ScrollableCanvasContainer</strong> which helps us draw coordinates, a grid, and the axis itself, it also allows users to customize their appearance and behavior according to their needs. Some of the other reusable components include</p><ol><li><strong>ScrollableCanvasContainer</strong>: ScrollableCanvasContainer is a container used to draw any graph which supports scroll, zoom, tap, or drag gestures. This composable is used to draw the chart background, to draw the axis, and the chart itself. developers can reuse or customize the appearance of the chart by changing the Modifier and various user interactions can be addressed by the callbacks provided such as onScroll.</li></ol><pre>ScrollableCanvasContainer(<br>    modifier: Modifier,<br>    calculateMaxDistance: DrawScope.(Float) -&gt; Float,<br>    onDraw: DrawScope.(Float, Float) -&gt; Unit,<br>    drawXAndYAxis: @Composable BoxScope.(Float, Float) -&gt; Unit,<br>    containerBackgroundColor: Color = Color.White,<br>    layoutDirection: LayoutDirection = LayoutDirection.Ltr,<br>    onPointClicked: (Offset, Float) -&gt; Unit = { _, _ -&gt; },<br>    isPinchZoomEnabled: Boolean = true,<br>    onScroll: () -&gt; Unit = {},<br>    onZoomInAndOut: () -&gt; Unit = {},<br>    scrollOrientation: Orientation = Orientation.Horizontal<br>)</pre><ol><li><strong>XAxis</strong>: XAxis compose method used for drawing xAxis in any given graph. Along with the Modifier, the xAxisData parameters enables developers to extensively customize Xaxis being displayed, AxisData is another re-usable model used to customize both the axis appearance and behavior, the following snippet shows the other customizations offered by xAxis composable.</li></ol><pre>@Composable<br>fun XAxis(<br>    xAxisData: AxisData,<br>    modifier: Modifier,<br>    xStart: Float,<br>    scrollOffset: Float,<br>    zoomScale: Float,<br>    chartData: List&lt;Point&gt;,<br>    axisStart: Float<br>)</pre><ol><li><strong>YAxis</strong>: YAxis compose method used for drawing yAxis in any given graph. similar to xAxis, the Modifier, and the yAxisData parameters enable developers to extensively customize Yaxis being displayed, other customizable options are shown in following snippet.</li></ol><pre>@Composable<br>fun YAxis(<br>    modifier: Modifier,<br>    yAxisData: AxisData,<br>    scrollOffset: Float = 0f,<br>    zoomScale: Float = 0f,<br>    chartData: List&lt;Point&gt; = emptyList(),<br>    dataCategoryWidth: Float = 0f,<br>    yStart: Float = 0f,<br>    barWidth: Float = 0f<br>)</pre><ol><li><strong>AccessibilityBottomSheetDialog</strong>: The bottom sheet dialog appears when the accessibility-talk-back option is enabled in the phone settings.<br>The bottom sheet shows items in a vertical list view with a close button at the top.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/270/1*q31pz0-KMlXz30xBIq4g5w.jpeg" /><figcaption>AccessibilityBottomSheetDialog is shown for a line chart when accessibility talk-back is enabled.</figcaption></figure><ol><li><strong>Legends</strong>: Chart legends are a crucial component of data visualization that provides information about the various colors, attributes, symbols, and data points used in a chart. “Legends” is a composable re-usable component, which renders the list of legends in a grid format for the given grid column count, LegendsConfig along with the Modifier enables users to customize the appearance.</li></ol><pre>@Composable<br>fun Legends(modifier: Modifier = Modifier, legendsConfig: LegendsConfig)</pre><h4>Compose Multiplatform and Y-Charts</h4><p>Compose Multiplatform is a modern UI declarative framework by JetBrains, based on Kotlin Multiplatform and Jetpack Compose, a modern UI toolkit for building native Android applications. Compose Multiplatform enables the development of cross-platform libraries that can be used across Android and iOS. By utilizing Compose Multiplatform, Y-Charts can share common code logic, data models, and rendering components across platforms. This approach streamlines the development process, reduces duplication of efforts, and ensures a consistent user experience across different platforms. Developers can easily create interactive and visually appealing charts by leveraging the declarative nature and powerful ability of Jetpack Compose.</p><p><a href="https://github.com/yml-org/kmm-ycharts">kmm-ychart</a>s is a dedicated repository for the Kotlin Multiplatform version of the Ycharts Android library.</p><p><a href="https://github.com/yml-org/kmm-ycharts">GitHub - yml-org/kmm-ycharts: Cross platform repository</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/293/1*6ZQ5lWoy0AlPqvczPJYoWA.png" /></figure><h4>Opensource Contributors:</h4><p>1. @<a href="https://github.com/kikoso">kikoso:</a>Enrique López Mañas<br>2. @<a href="https://github.com/dkk009">dkk009: </a>Deepak KK<br>3. @<a href="https://github.com/Margin-KS">Margin-KS</a><br>4. @<a href="https://github.com/sreekuttan-yml">sreekuttan-yml: </a>Sreekuttan<br>5. @<a href="https://github.com/preetham1316">preetham1316: </a>Preetham Ivan Dsouza<br>6. @<a href="https://github.com/alexandre-thauvin">alexandre-thauvin: </a>Alexandre Thauvin<br>7. @<a href="https://medium.com/u/11afc146ad7f">Codeangi</a>: Ananthakrishna<br>8. @<a href="https://github.com/HKIRA00">HKIRA00</a>: Harsha Kiran<br>9. @<a href="https://github.com/krishanjangir-yml">krishanjangir-yml</a>: Krishan Jangir<br>10. @<a href="https://github.com/jay607">jay607</a>: Jay Challa<br>11. @<a href="https://github.com/xyzwilliamxyz">xyzwilliamxyz</a>: William</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2568aeac19fb" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ymedialabs-innovation/meet-ycharts-an-opensource-jetpack-compose-chart-library-2568aeac19fb">Meet “YCharts”: an Opensource Jetpack Compose chart library.</a> was originally published in <a href="https://medium.com/ymedialabs-innovation">YML Innovation Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[(KMM- Ktor) Multiplatform Networking]]></title>
            <link>https://codeangi.medium.com/kmm-ktor-multiplatform-networking-7997061cc85a?source=rss-11afc146ad7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/7997061cc85a</guid>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[ktor]]></category>
            <category><![CDATA[networking]]></category>
            <dc:creator><![CDATA[Codeangi]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 09:38:49 GMT</pubDate>
            <atom:updated>2023-02-21T09:38:49.095Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4aBfRqsFco67-aiA1EFFmg.png" /><figcaption>src: <a href="https://github.com/ktorio/ktor">https://github.com/ktorio/ktor</a></figcaption></figure><p>“<a href="https://ktor.io/">Ktor</a> is a framework to easily build connected applications — web applications, HTTP services, mobile and browser applications. Modern connected applications need to be asynchronous to provide the best experience to users, and Kotlin coroutines provide awesome facilities to do it in an easy and straightforward way. The goal of <a href="https://ktor.io/docs/welcome.html">Ktor</a> is to provide an end-to-end multiplatform framework for connected applications.”</p><p><strong>Ktor for multiplatform</strong></p><p>Using <strong>Ktor</strong> we can create our own HTTP client to interact with remote servers, typically we will be using a <strong>content negotiation</strong> &amp; <strong>serialization</strong> plugin to parse Raw Network Response into a usable DTO. <strong>OkHttp</strong> is a popular network client used by the Android community extensively, it provides finer control over network interactions, similarly, <strong>darwin</strong> client is used in iOS/Native for network interactions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*71wLt40HzZiqlBtSYRsA5A.gif" /></figure><h3>What are network Engines?:</h3><p>“The Ktor HTTP client can be used on different platforms, including JVM, Android, JavaScript, and Native. A specific platform may require a specific engine that processes network requests. For example, you can use Apache or Jetty for JVM applications, OkHttp or Android for Android, Curl for desktop applications targeting Kotlin/Native, and so on. Different engines may have specific features and provide different configuration options.”</p><p>Each engine comes with its own limitations and configurations some can be found here: <a href="https://ktor.io/docs/http-client-engines.html#limitations">Engines | Ktor</a></p><ul><li>If an engine supports HTTP/2, you can enable it by customizing the engine configuration (see an example for the Java engine).</li><li>To configure SSL in the Ktor client, you need to customize the configuration of a selected engine.</li><li>Some engines don’t support proxy.</li><li>The Logging plugin provides different logger types for different platforms.</li><li>The HttpTimeout plugin has some limitations for specific engines.</li><li>The XML serializer is supported on JVM only.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*T-ST4u_Zn2CIF4yxx-yJhg.png" /></figure><h3>Setting up Ktor with OkHttp Engine for Android:</h3><p>A JVM/Android client engine that uses the OkHttp HTTP client. This engine supports Android 5.0 and newer.</p><p>To configure the engine, pass the settings exposed by <a href="https://api.ktor.io/ktor-client/ktor-client-okhttp/io.ktor.client.engine.okhttp/-ok-http-config/index.html">OkHttpConfig</a> to the engine method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a3c6cdf0a3b3a2e76936dc83ea9c9d8/href">https://medium.com/media/2a3c6cdf0a3b3a2e76936dc83ea9c9d8/href</a></iframe><h3>Setting up Ktor with Darwin Engine for iOS:</h3><p>A Kotlin/Native client engine that targets Darwin-based operating systems (such as macOS, iOS, tvOS, and so on) and uses NSURLSession internally. To configure the engine, pass the settings exposed by <a href="https://api.ktor.io/ktor-client/ktor-client-darwin/io.ktor.client.engine.darwin/-darwin-client-engine-config/index.html">DarwinClientEngineConfig</a> to the engine method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f6de3e929b316e27b28563541584b10a/href">https://medium.com/media/f6de3e929b316e27b28563541584b10a/href</a></iframe><h3>How to integrate Ktor into a KMM project:</h3><p>In order to integrate Ktor into a KMM project, we need to add respective dependencies in <strong>build.gradle.kts</strong> file of the shared module/KMM Library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/8ac95265a38282efd92b05552dfdb4a1/href">https://medium.com/media/8ac95265a38282efd92b05552dfdb4a1/href</a></iframe><p>Once the dependencies are set, its time to configure our network client, this is done by first declaring a <strong>expect</strong> function for HttpClient inside commonMain sourceSet (standard practice to do it in Platform.kt ), this will let us implement platform-specific implementation for OkHttp and Darwin network clients in androidMain and iosMain respectively.</p><p><strong>commonMain→ Platform.kt</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/76cfafbf5394fc5190c741f09e91e400/href">https://medium.com/media/76cfafbf5394fc5190c741f09e91e400/href</a></iframe><p><strong>androidMain→ Platform.kt</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a4e40e6590af4b1039dbcb699cfe1484/href">https://medium.com/media/a4e40e6590af4b1039dbcb699cfe1484/href</a></iframe><p><strong>iosMain→ Platform.kt</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/507bbfca0f64cb320d8daf88668eb48e/href">https://medium.com/media/507bbfca0f64cb320d8daf88668eb48e/href</a></iframe><p>Once we have the Network client setup, we can configure our content negotiation to parse JSON responses, then we can use it to make network requests, we can also enable logging to visualize network transactions (optional).</p><p>We can use Kotlin <a href="https://kotlinlang.org/docs/multiplatform-mobile-concurrency-and-coroutines.html">Coroutines</a> to make the network call asynchronous.</p><blockquote><strong><em>org.jetbrains.kotlinx:kotlinx-coroutines-core</em></strong><em> dependency is needed (commonMain </em><strong><em>sourceSet</em></strong><em>) in order to use </em><a href="https://kotlinlang.org/docs/multiplatform-mobile-concurrency-and-coroutines.html"><em>Coroutines</em></a><em> inside shared code.</em></blockquote><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/442191458c34858d9f881d2d8da667fa/href">https://medium.com/media/442191458c34858d9f881d2d8da667fa/href</a></iframe><p><strong>How to specify a request URL?</strong></p><p>The Ktor client allows you to configure a request URL in the following ways:<br><strong>a. Pass the entire URL as String</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/914217b3dc1300ebaf4509e9a43d9e12/href">https://medium.com/media/914217b3dc1300ebaf4509e9a43d9e12/href</a></iframe><p><strong>b. Configure URL components separately</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0da5ba57172b643f527fbbb87745166a/href">https://medium.com/media/0da5ba57172b643f527fbbb87745166a/href</a></iframe><p><strong>How to add query parameters to a request?</strong></p><p>To add query string parameters, use the URLBuilder.parameters property:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/493f0faa076fb474e9448216940e11b6/href">https://medium.com/media/493f0faa076fb474e9448216940e11b6/href</a></iframe><h4><strong>How to add Headers</strong> to the request?</h4><p>The headers function allows you to add several headers at once:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9c2c090f36e54cba48f1fd5ee703dbbe/href">https://medium.com/media/9c2c090f36e54cba48f1fd5ee703dbbe/href</a></iframe><h4>How to send an Object as a Json request Body?</h4><p>With the enabled ContentNegotiation plugin, you can send a class instance within a request body as JSON. To do this, pass a class instance to the setBody function and set the content type to application/json using the contentType function:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9acd2c416f2503e6c88cb2c4c03d9bf/href">https://medium.com/media/f9acd2c416f2503e6c88cb2c4c03d9bf/href</a></iframe><blockquote><em>For more : See documentation: </em><a href="https://ktor.io/docs/request.html#text"><em>https://ktor.io/docs/request.html#text</em></a></blockquote><h3>Network Transactions:</h3><p><strong>HTTP Methods:</strong></p><p>We can specify http method (GET, POST, PUT, DELETE, HEAD, OPTION, or PATCH) by-supplying <strong>method</strong> property inside the request block.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/1802b67841bffa3e622dd2cffbe8751e/href">https://medium.com/media/1802b67841bffa3e622dd2cffbe8751e/href</a></iframe><blockquote><em>For more : See documentation: </em><a href="https://ktor.io/docs/request.html#text"><em>https://ktor.io/docs/request.html#text</em></a></blockquote><h3>Usage:</h3><p>Once we add the intended KMM library as dependency into the Android and iOS application (check : <a href="https://www.notion.so/KMM-Writing-Shareable-Code-016f464ff8b6458c9d86fc1886d5ee2a">Writing Sharable Code</a> for more details), we can consume <strong>searchForMovieWithTitle</strong> an exposed method.</p><p>How to make a Network request from A<strong>ndroid?</strong></p><p>In Android, suspend functions can be only called by other suspend functions or from a coroutine block. Typically data transactions calls are done via <strong>ViewModel,</strong></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f97af433f1fb0fbeba85a36ae6890acb/href">https://medium.com/media/f97af433f1fb0fbeba85a36ae6890acb/href</a></iframe><p><strong>iOS</strong></p><p>Similarly in iOS <strong>ViewModel</strong> is the typical location to make network calls, the same <strong>searchForMovieWithTitle</strong> method can be used in iOS, and results can be consumed in a callback.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63d7fa385dcfd60c3d91c6a6eae6e664/href">https://medium.com/media/63d7fa385dcfd60c3d91c6a6eae6e664/href</a></iframe><p>If you found it helpful, these are the related articles:<br>1.<a href="https://medium.com/@InfinateDarkness/start-kmm-getting-the-settings-right-fcc1f076a35a"> Getting the settings right: setting up for KMM</a><br>2. <a href="https://medium.com/@InfinateDarkness/kmm-writing-shareable-code-6b25a5a85b12">Sharing Code: with KMM</a><br>3. <a href="https://medium.com/@InfinateDarkness/kmm-start-of-a-journey-a-look-into-kotlin-multiplatform-mobile-1a26cb50ca67">KMM: Whats on the plate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7997061cc85a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Start KMM→ Getting the Settings right.]]></title>
            <link>https://codeangi.medium.com/start-kmm-getting-the-settings-right-fcc1f076a35a?source=rss-11afc146ad7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fcc1f076a35a</guid>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Codeangi]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 09:37:38 GMT</pubDate>
            <atom:updated>2023-02-21T09:37:38.659Z</atom:updated>
            <content:encoded><![CDATA[<p>As we saw in our previous encounter with Kotlin Multiplatform Kotlin offers a great ability to share code, when it comes to Kotlin Multiplatform-Mobile, or KMM for short, we can write business logic in Kotlin as sharable code and expose functionality via APIs.</p><p>Kotlin Multiplatform Mobile is in <a href="https://kotlinlang.org/docs/components-stability.html">Beta</a>. Language features and tooling may change in future Kotlin versions.</p><h3>Tooling:</h3><p><strong>IntelliJ IDEA</strong> is an integrated development environment (IDE) written in Java for developing computer software written in Java, Kotlin, Groovy, and other JAR-based languages. It is developed by JetBrains (formerly known as IntelliJ), a powerful tool for Kotlin development that offers many standard IDE features along with Kotlin-oriented plugins to enable KMM development.</p><p><strong>Android Studio</strong> is Based on <strong>IntelliJ</strong> IDEA and also offers an integrated environment to develop and deploy android applications and libraries, with the KMM plugin we can create shareable modules and integrate them into Android and iOS platforms.</p><blockquote><em>required: </em><a href="https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile"><em>KMM plugin</em></a></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/1*46mJcnFhHxyuOcZkuhCdnQ.png" /><figcaption>source:<a href="https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile">https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile</a></figcaption></figure><h3>How to share KMM code with Android and iOS?</h3><ul><li><strong>As KMM Module</strong>: Using <strong>Android studio</strong> we can create an integrated project with Android, iOS, and Shared code which gives us a sample project template with the shared module already integrated into to respective application, We can deploy the iOS application from the android studio with the help of Xcode Command Line tools (Mac OS is required to build and run the iOS application).</li><li><strong>As KMM Library</strong>: If we wish to keep the shared codebase separate and have a dedicated distribution channel, we can choose to configure our project as a KMM Library, which will omit any application-related code and expose functionalities APIs that can be integrated into any application as a library (.xcf/swift/cocoa pod framework for iOS, and JAR/AAR for Android).</li></ul><h3>How to set up KMM development?</h3><p>Requirements:</p><ul><li>Install <a href="https://developer.android.com/studio">Android Studio</a> — 4.2 or 2020.3.1 Canary 8 or higher.</li><li>Install <a href="https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile">KMM plugin</a> — Go to AndroidStudio→ Preferences → Plugins search for the plugin Kotlin Multiplatform Mobile in Marketplace and install it.</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*cRmxZeqsH1AmHPO4ZuKC-Q.png" /></figure><p>For iOS-specific code and run an iOS application, <a href="https://apps.apple.com/us/app/xcode/id497799835">Xcode</a> — version 11.3 or higher needs to be installed, once installed make sure Command Line Tools is set to the installed Xcode version, go to Xcode → Preferences → Locations → Command Line Tools.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RXbBxmrQrh6C7wsmyazISQ.png" /></figure><h3>To create a Kotlin Multiplatform Application:</h3><ol><li>Open Android Studio → File → New → New Project → Choose Kotlin Multiplatform Application from the templates. Click on Next.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*W3gihdmAvkapZKMPti7hiQ.png" /></figure><p>2. Choose an appropriate name for your project/application, a package name for identification, and a minimum android SDK, Click on Next.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*aUP5fCWPgrMwtfS6N-5l9Q.png" /></figure><p>3. Next, Choose appropriate names for the Android application, iOS Application, and the Shared module, Choose an iOS distribution type (We choose Regular framework in this case)and click on “Finish”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*za30Nlq5CIvl0LltRGsJNQ.png" /></figure><p>It’s ready;]</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*gcVXb1dbYiw8zgZG214ukw.png" /></figure><p>To See the whole content of the project, once you have configured KMM Application, switch explorer to show “Project”.</p><p><strong>What do you see here: KMM Project template anatomy.</strong></p><ol><li><strong>MyKMMApplication folder</strong>*: Root folder for the project.</li><li><strong>.gradle folder</strong>: The Gradle user home directory ( $USER_HOME/.gradle by default) is used to store global configuration properties and initialization scripts as well as caches and log files.</li><li><strong>android app folder</strong>*: Folder containing Android application-related files and code.<br>- <strong>build folder(App)</strong>: Android build output folder.<br>- <strong>src folder</strong>: Android App source code.<br>- <strong>build.gradle.kts file (App)</strong>: Dependency &amp; build configuration script for android application.</li><li><strong>build folder (Project)</strong>: Project build output folder.</li><li><strong>gradle folder</strong>: Contains gradle wrapper for creating and running project.</li><li><strong>iosApp folder</strong>*: Contains Xcode project and code related to the iOS application (Mac OS, Xcode is required to compile and run the iOS project)<br>- <strong><em>iosApp folder (inner)</em>*</strong>: ****Contains source code and libraries related to iOS Application.<br>- <strong>iosAPP.xcodeproj folde</strong>r: Contains iOS workspace and Xcode project configuration files.</li><li><strong>shared folder</strong>*: Folder containing shared KMM code.<br>- <strong>build folder</strong>: Build output folder for shared code.<br>- <strong>src folder</strong>: Source folder for containing shared code and code of target source sets (Android and iOS).<br> — <strong>androidMain folder</strong>: Contains platform-specific implementations and “<strong>actual”</strong> functions and classes for Android.<br> — <strong>commonMain folde</strong>r: Contains shared code, “<strong>expect”</strong> declarations.<br> — <strong>iosMain folder</strong>: Contains platform-specific implementations and “<strong>actual”</strong> functions and classes for iOS.<br>-<strong>build.gradle.kts file(Shared):</strong> Contains build configurations and source-set dependencies for target platforms.</li><li><strong>.gitignore file</strong>: Contains a list of files/folders to ignore when committing code to Git VCS.</li><li><strong>build.gradle.kts file(Project):</strong> Contains project-wide dependencies and project configuration.</li><li><strong>gradle.properties file</strong>: Properties file containing project configuration values and versioning constants.</li><li><strong>gradlew file</strong>: Gradle wrapper used to build and run files on Unix-based machines.</li><li><strong>gradlew.bat file</strong>: Gradle wrapper used to build and run files on Windows machines.</li><li><strong>local.properties file</strong>: Contains configuration values for local-machine specific SDK location/command line args</li><li><strong>settings.gradle.kts:</strong> Contains settings related to modules of project.</li><li><strong>External Libraries</strong>: Contains all the library dependencies for project.</li><li><strong>Scratches and consoles</strong>: Scratch files are fully functional, runnable, and debuggable files. They’re useful for drafting up code or running code in isolation. Alternatively, scratch buffers are plain text files. They’re useful for making quick notes, a to-do list, or frequently used strings.</li></ol><blockquote><em>*name configured during project creation</em></blockquote><h3>Running Applications:</h3><p>When we create a KMM project using android studio, it already contains a sample integration of the shared library, which returns a string containing platform details via Greeting class, and its all ready to run!</p><h3>1. Android</h3><p>To run the android application select androidApp in the run-configuration drop-down menu in android studio, choose or create an Android Emulator/ Connect a debuggable physical device, and hit “Run”.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/1*NwhrMi78hhqqOgC77anWGA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/556/1*-3HND94O5PRKDGXQxTRfKg.png" /></figure><h3>2. iOS(Mac OS):</h3><p>We can either choose to run the iOS App directly from the android studio or run it via Xcode, currently,iOS build is only possible via MacOs. To run the iOS application select iOSApplication in run-configuration drop-down menu in android studio, click on “Edit configuration” option to select desired iPhone/iPad simulator, click on “run” icon.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mZcMZM4josdtUFftU4AJdg.png" /></figure><p>We can also run iOS application via Xcode, in order to do this, select “iosApp.xcodeproj” → open in → Xcode→ and click on “Start active scheme”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XhY7FqagbRa6h3wxTyrnRQ.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*CNvWnFo3ofNl2FDGIsYJkw.png" /></figure><p><strong>Were you able to run?</strong></p><p>that’s great! you have just created a KMM application successfully.</p><p>If you found it helpful, these are the related articles:<br>1. <a href="https://medium.com/@InfinateDarkness/kmm-writing-shareable-code-6b25a5a85b12">Sharing Code: with KMM</a><br>2. <a href="https://medium.com/@InfinateDarkness/kmm-ktor-multiplatform-networking-7997061cc85a">Networking in KMM</a><br>3. <a href="https://medium.com/@InfinateDarkness/kmm-start-of-a-journey-a-look-into-kotlin-multiplatform-mobile-1a26cb50ca67">KMM: Whats on the plate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fcc1f076a35a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KMM Writing Shareable Code]]></title>
            <link>https://codeangi.medium.com/kmm-writing-shareable-code-6b25a5a85b12?source=rss-11afc146ad7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/6b25a5a85b12</guid>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin]]></category>
            <category><![CDATA[mobile-app-development]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <dc:creator><![CDATA[Codeangi]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 09:36:36 GMT</pubDate>
            <atom:updated>2023-02-21T09:36:36.000Z</atom:updated>
            <content:encoded><![CDATA[<p>Kotlin Multiplatform Mobile is in <a href="https://kotlinlang.org/docs/components-stability.html">Beta</a>. Language features and tooling may change in future Kotlin versions.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/247/1*Q8JKUSXpoRbE8Q5VIIDJdA.jpeg" /></figure><p>Optional code sharing brings out many new opportunities to developers, as we get to choose precisely how much we want to share. In any typical application regardless of the platform, core data layer remains almost the same, CRUD operations in local or over the network will result in similar DTO across platforms, leveraging on this we can determine a modular approach to make such transactions as a shared library. Similarly the Utility functions and business logic itself can be written in Kotlin and can be exposed via APIs for applications to consume.</p><p>Although there is scope for more sharable components, popular choice is to play it safe and keep presentation and UI logic at the helm of platform-native code.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/700/1*m99n88i48tRnlxkwuTl22w.png" /></figure><h3>Where do we start?</h3><p>When we create a new KMM project via Android Studio, the project will contain some basic code integrated already, this is enough to give us an idea of how KMM shared module is written.</p><p>The first thing we notice here is the different source sets {<strong>androidMain, commonMain, and iosMain</strong>}, these folders are created based on our target-platforms, defined in <strong>build.gradle.kts</strong> file of the shared module/KMM Library. If we target more than just iOS and Android corresponding source-sets will be created for each of the targets.</p><p>Respective source-sets will contain platform-specific implementation and or “<strong>actual”(Platform.kt file)</strong> members for each of the “<strong>expect</strong>” members declared in the commonMain source-set**(Platform.kt file)**.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1008/1*gcVXb1dbYiw8zgZG214ukw.png" /></figure><h3>How to Configure Sourcesets in KMM?</h3><p>In order to generate source-sets we need to add respective targets in <strong>build.gradle.kts</strong> file of the shared module/KMM Library, here we see android and iOS targets defined, there is also support for different architecture offered by iOS such as X64, ARM, etc.. developers can optionally choose what architecture is supported (based on Kotlin/Native compatibility). Android and iOS templates are automatically added by Android Studio when we create a KMM project.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/405f58e71613decf85863bfd60f2c485/href">https://medium.com/media/405f58e71613decf85863bfd60f2c485/href</a></iframe><p>Each of the targets will have a corresponding sourceSet associated with it here we can define library/module dependency on each of the sourceSets, optionally developers can even have <strong>TestSourceSets</strong> for maintaining Unit tests for functions in each of the sourceSets.</p><p>here <strong>iosX64Main, iosArm64Main, and iosSimulatorArm64Main</strong> are combined into <strong>iosMain</strong> sourceSet as they share similar dependencies in this scope.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/73bdc8f457ccff8398abab95470267f6/href">https://medium.com/media/73bdc8f457ccff8398abab95470267f6/href</a></iframe><h3>How to share logic between platforms in KMM?</h3><p><strong>commonMain</strong> sourceSet contains all the shared implementations, common for all the target platforms. Here we write APIs/functions and expose them for consumption by the target application. When we create a KMM project in android studio, the template will contain an example implementation of a shared method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/66b2318ab4ace64d134f8f6bd1144b0a/href">https://medium.com/media/66b2318ab4ace64d134f8f6bd1144b0a/href</a></iframe><p>As we can see in the above example, greeting() method returns a string composition, which has a value obtained from Platform().platform ;</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb0ebcb07983f77db4c69a57dcc3011/href">https://medium.com/media/7bb0ebcb07983f77db4c69a57dcc3011/href</a></iframe><h3>What are expect &amp; actual in KMM?</h3><p>Class <strong>Platform</strong> Which is declared as an “<strong>expect</strong>” class inside the commonMain <strong>Platform.kt</strong> class, an <strong>expect keyword</strong> illustrates respective <strong>declaration</strong> will have an “<strong>actual</strong>” <strong>implementation</strong> in all the target sourceSets, this helps us to connect Platform-specific code to the common code.</p><p>“<strong>expect &amp; actual”</strong> are required when we intend to use any system/platform specific functionality such as httpClient, database drivers. “<strong>expect &amp; actual”</strong> methodology also helps to connect exclusive implementation of Kotlin/Native, Kotlin/JVM, Kotlin/JS into common use-cases.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e8490be81528fbf0e379f706534c0577/href">https://medium.com/media/e8490be81528fbf0e379f706534c0577/href</a></iframe><p>as we can see in the above example, class Platform’s <strong>actual</strong> implementation is required for both <strong>androidMain</strong> and <strong>iosMain</strong> sourceSets as we have an <strong>expect</strong> declaration in <strong>commonMain</strong> sourceSet.</p><h3>Using KMM library as a platform-native library:</h3><p>Shared functionality can be exposed for consumption via public properties via classes inside the <strong>commonMain</strong> sourceSet. Generated code is basically a library, now we have option to use the generated KMM library as a regular platform-native library on to the target application. Following are the some of popular way of publishing as platform-native library.</p><h3><a href="https://kotlinlang.org/docs/multiplatform-publish-lib.html#publish-an-android-library">Android:- Publishing KMM library to Maven Repo</a></h3><p>Maven is a popular distribution channel for android, in order to publish our library using Maven repo, we need to add maven-publish plugin to <strong>build.gradle.kts</strong> file of the shared module/KMM Library.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/fd7d7e897420b391fa964cf01b648bcb/href">https://medium.com/media/fd7d7e897420b391fa964cf01b648bcb/href</a></iframe><p>Once added and gradle sync is successful, we can click on gradle options from the Android Studio to choose whether to publish to a local maven repo or a remote one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PKGk2gmgXXlq2NNUNjfEUg.png" /></figure><p><strong>How to use the published KMM library Android?</strong></p><p>Once published to a Maven repository, we can <strong>add</strong> a dependency in <strong>build.gradle</strong> file of the target android application, and consume exposed functionality wherever necessary.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7ddea3e10edebe1dff427c6c66402916/href">https://medium.com/media/7ddea3e10edebe1dff427c6c66402916/href</a></iframe><h3><a href="https://www.swift.org/package-manager/">iOS- Publishing KMM library as a Swift package</a></h3><p>One of the popular distribution methods for iOS is to export the library as a swift package and import into application project from GitHub.</p><p>Popular way for exporting KMM library into a swift package involves a plugin <a href="https://github.com/ge-org/multiplatform-swiftpackage">https://github.com/ge-org/multiplatform-swiftpackage</a> through which we can create a swift package. once we add the plugin, we can configure and customize some of the swift package data such as name, version and output directory etc..</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9999b97d41d5d580552810a4a57fa679/href">https://medium.com/media/9999b97d41d5d580552810a4a57fa679/href</a></iframe><p>Once multiplatform-swift package is added and configured, synchronise the project and using gradle options from Android Studio, we can create a Swift package which will be generated inside pre-defined output directory. Once swift package is generated, we can upload into any distribution channels like github and in Xcode we can import the package via URL.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L0seSA5uRue9ECrdEj-V_Q.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/984/1*BzKpSCnl01fVvYvQwT9c-w.png" /></figure><p><strong>How to Use it in iOS?</strong></p><p>One Package dependency is added in Xcode, we can import the said library on to our swift file and use exposed functionality.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2ef7b34417cefedef752986904be220f/href">https://medium.com/media/2ef7b34417cefedef752986904be220f/href</a></iframe><p>If you found it helpful, these are the related articles:<br>1.<a href="https://medium.com/@InfinateDarkness/start-kmm-getting-the-settings-right-fcc1f076a35a"> Getting the settings right: setting up for KMM</a><br>2. <a href="https://medium.com/@InfinateDarkness/kmm-ktor-multiplatform-networking-7997061cc85a">Networking in KMM</a><br>3. <a href="https://medium.com/@InfinateDarkness/kmm-start-of-a-journey-a-look-into-kotlin-multiplatform-mobile-1a26cb50ca67">KMM: Whats on the plate</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6b25a5a85b12" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[KMM: What's Under the hood?]]></title>
            <link>https://medium.com/ymedialabs-innovation/kmm-whats-under-the-hood-1a26cb50ca67?source=rss-11afc146ad7f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a26cb50ca67</guid>
            <category><![CDATA[mobile-development]]></category>
            <category><![CDATA[kotlin-beginners]]></category>
            <category><![CDATA[kotlin-multiplatform]]></category>
            <category><![CDATA[kotlin]]></category>
            <dc:creator><![CDATA[Codeangi]]></dc:creator>
            <pubDate>Tue, 21 Feb 2023 09:35:23 GMT</pubDate>
            <atom:updated>2023-03-02T21:03:33.088Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/250/1*Jkira27wCRIOfq_2GIZ2QA.png" /><figcaption><a href="https://plugins.jetbrains.com/plugin/14936-kotlin-multiplatform-mobile">source</a></figcaption></figure><p>There have been many tools for cross-platform development before but offered so little in terms of sharable code, there was always an overhead of writing and maintaining applications in a set-predetermined technology such as Phonegap, ReactNative, and Flutter.</p><p>Kotlin provides a huge leeway in writing sharable code, especially when you are developing Mobile applications for Android and iOS with similar features. In the real world, it translates into <strong>fewer lines of code</strong>, <strong>fewer bugs</strong>, <strong>less tim</strong>e, and of course <strong>lesser</strong> <strong>cost of development</strong>. Whether you are starting a new project or adding a new feature to an existing one.</p><blockquote>This article is an effort to interpret <strong>KMM</strong> in layman’s terms, knowing programming helps but is not mandatory.</blockquote><blockquote>Topics Include: What is KMM, How it works, the Good, and the Bad.</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PzGC52HPRdzQWi50X5F85A.png" /><figcaption><a href="https://commons.wikimedia.org/wiki/File:Kotlin_Icon.svg">source</a></figcaption></figure><p><a href="https://kotlinlang.org/"><strong>Kotlin</strong></a> is a cutting-edge yet established programming language that offers a range of benefits for developers. One of the key use cases for Kotlin is its ability to share code between mobile platforms through Kotlin Multiplatform Mobile (KMM). By using KMM, developers can create cross-platform mobile apps and share crucial elements like business logic, data, and connectivity implementation between Android and iOS.</p><h3>Kotlin-Native</h3><p>In order to use Kotlin code in iOS, the Kotlin code is first compiled to LLVM bytecode using the Kotlin/Native compiler. <a href="https://llvm.org/">LLVM</a> (Low Level Virtual Machine) is a collection of modular and reusable compiler and toolchain technologies.</p><p>The LLVM bytecode is then compiled using the iOS toolchain and linked with the iOS runtime libraries.</p><p>The resulting binary is an iOS application bundle (an .app directory) that contains the Kotlin code and the Swift runtime. When the app is run, the Swift runtime loads the Kotlin code and uses it as if it were native Swift code.</p><h3><a href="https://kotlinlang.org/docs/js-overview.html">Kotlin/JS</a></h3><p>Kotlin/JS provides the ability to trans-compile Kotlin code, the Kotlin standard library, and any compatible dependencies to JavaScript. The current implementation of Kotlin/JS targets <a href="https://www.ecma-international.org/ecma-262/5.1/">ES5</a>. The Kotlin/JS compiler converts the Kotlin code into JavaScript code that can be executed by the JavaScript engine in the browser.</p><p>The process of compilation starts with the Kotlin code, which is then transformed into an intermediate representation (IR) by the Kotlin compiler. The IR code is then passed through a set of optimization passes that improve the performance of the generated JavaScript code. After that, the IR is translated into JavaScript code, which can be run in a web browser.</p><h3><a href="https://kotlinlang.org/docs/jvm-get-started.html">Kotlin/JVM</a></h3><p>Kotlin is 100% interoperable with the Java programming language and provides easy access to existing java-code/libraries. Popularly used as a java replacement, <a href="https://developer.android.com/kotlin/first">Android</a> has officially announced its Kotlin-first policy, recognizing its importance.</p><h3><a href="https://kotlinlang.org/docs/multiplatform.html#kotlin-multiplatform-use-cases">How KMM is used?</a></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*y9NdHeYCkLqwURWkBfoU9g.png" /></figure><h3>Android and iOS applications</h3><p>With Kotlin Multiplatform Mobile, you can build cross-platform mobile applications and share common code between Android and iOS, such as business logic, connectivity, and more.</p><h3>Multiplatform libraries</h3><p>Kotlin Multiplatform is also useful for library authors. You can create a multiplatform library with common code and its platform-specific implementations for JVM, JS, and Native. Once published, a multiplatform library can be used in other cross-platform projects as a dependency.</p><p>Check out some of them already listed here:</p><p><a href="https://libs.kmp.icerock.dev/">Kotlin Multiplatform Libraries</a></p><h3>Common code for mobile and web applications</h3><p>One more popular case for using Kotlin Multiplatform is sharing the same code across Android, iOS, and web apps. It reduces the amount of business logic coded by front-end developers and helps implement products more efficiently, decreasing the coding and testing efforts.</p><h3>What to share?</h3><p>Developers get to choose what to share in KMM, so we can identify parts of the application that are common, such as <strong>Data</strong> (Network-response &amp; or Local DB), <strong>Business Logic</strong> which is usually the same across platforms, these are the ideal candidate for shared modules. KMM also provides the experimental ability to share <strong>ViewModels</strong> and <strong>Views</strong>(in the works). So developers get the flexibility to choose how much code is shared, and customize how it is integrated on target platforms, this helps to keep the project concise and maintainable on the scale.</p><h4>Swift InterOp</h4><p>When Kotlin code is compiled, into Kotlin/native library, some nuances which may differ implementation-wise w.r.t Objective-C/Swift, are mapped to an equivalent class with similar behavior.</p><p>they can be found in Kotlin&#39;s official documentation</p><p><a href="https://kotlinlang.org/docs/native-objc-interop.html#mappings">https://kotlinlang.org/docs/native-objc-interop.html#mappings</a></p><h3>Where is Kotlin Multiplatform Mobile now?</h3><p>First Released in <a href="https://blog.jetbrains.com/kotlin/2020/08/kotlin-multiplatform-mobile-goes-alpha/">August 2020</a>, KMM has been on an accelerated path of growth, since it’s release there have been <strong>19</strong> major releases/updates currently at the time of this article the stable release is <strong>0.5.1</strong> which offers many features and tools for seamless integration across Android and iOS devices.</p><h3>Why choose KMM over another cross-platform tech?</h3><ul><li>Cross-platform techs like ReactNative (JS), flutter, Ionic, and PhoneGap comes with a technical overhead, they require the whole application code including the UI/UX to be written in the same environment/language, which requires a dedicated development effort and developer dependency.</li><li>Suitable for Test-Driven Development.</li><li>Cross-platform tech is always prone to inconsistencies in terms of UI/UX and performance compared to Platform-Native applications.</li><li>Kotlin Multiplatform enables developers to partly or optionally share the code, which can collectively reduce development effort by up to 50% when used in a multi-platform setup, without compromising the performance and user experience.</li><li>KMM libraries can be used to modularize and maintain precise and concise code, easy to share and integrate into existing applications.</li><li>Suitable for plug-and-play modules with little dependency on UI.</li></ul><h3>What are the drawbacks of KMM?</h3><p>Though some of these are not just unique to KMM, should be acknowledged nonetheless.</p><ul><li>The major drawback is you still need Mac OS to compile and run iPhone/iPad applications.</li><li><strong>No Code-Documentation</strong>. If you are a native developer you must be used to accessing handy documentation in AS/XCode, but when you are using KMM library in Xcode, you might be deprived of that luxury for now.</li><li>Though there is no noticeable run-time latency, there is a slight impact on compile time in iOS when developing KMM App, in XCode. (I’d give this a break though, switching IDEs is not smooth, so it is expected to have some compile-time issues.)</li><li>Custom classes implementing standard Kotlin collection interfaces (List, Map, Set) and other special classes are not supported in objective-c/swift.</li><li><strong>Swift-class Mapping</strong>, Kotlin data classes are not supported in swift, so is the case for some of the other Kotlin-nuances(data classes, interfaces, sealed classes, nil/null etcetera..). Such features are mapped to equivalent swift implementations. this might take some time to get used to guessing the correct name/notation for such expressions.</li></ul><p>At <a href="https://medium.com/u/27c68031e2b7">YML</a> we have been using #KMM and it has received a positive response from the developers. It is easy to adapt to existing projects, and with rapid growth, KMM has a very bright future in <strong>Allied-Native-Development</strong>. A New Kind of development where Android and iOS native developers can collaborate more and learn a thing or two about the platforms of the counterpart and Share the code. Still, there is more exciting stuff coming our way from the KMM.</p><p>Thank you <a href="https://medium.com/u/f08187f6a023">Enrique López-Mañas</a> and <a href="https://medium.com/u/77641d84ddda">Duc Haba</a> for your valuable insights on the article.</p><p>If you found it helpful, these are the related articles:<br>1.<a href="https://medium.com/@InfinateDarkness/start-kmm-getting-the-settings-right-fcc1f076a35a"> Getting the settings right: setting up for KMM</a><br>2. <a href="https://medium.com/@InfinateDarkness/kmm-writing-shareable-code-6b25a5a85b12">Sharing Code: with KMM</a><br>3. <a href="https://medium.com/@InfinateDarkness/kmm-ktor-multiplatform-networking-7997061cc85a">Networking in KMM</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a26cb50ca67" width="1" height="1" alt=""><hr><p><a href="https://medium.com/ymedialabs-innovation/kmm-whats-under-the-hood-1a26cb50ca67">KMM: What&#39;s Under the hood?</a> was originally published in <a href="https://medium.com/ymedialabs-innovation">YML Innovation Lab</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>