Skip to content

Commit

Permalink
gears: added package with set of gears for compose
Browse files Browse the repository at this point in the history
  • Loading branch information
sonulen committed May 27, 2024
1 parent 9d63294 commit 25bae5f
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions config/detekt/detekt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,7 @@ naming:
active: true
excludes: ['**/test/**', '**/androidTest/**', '**/commonTest/**', '**/jvmTest/**', '**/jsTest/**', '**/iosTest/**']
functionPattern: '([a-z][a-zA-Z0-9]*)|(`.*`)'
ignoreAnnotated: ['Composable']
excludeClassPattern: '$^'
FunctionParameterNaming:
active: true
Expand Down
3 changes: 3 additions & 0 deletions gears/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// For some reason gradle.properties in this project doesn't affect its subprojects
val gearsGroup = group
subprojects { group = gearsGroup }
7 changes: 7 additions & 0 deletions gears/compose/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
## Unreleased

### Changed

- Create gears.compose
added:
- `FixedFontScaleContainer` - A container that fixes the font scale, ignoring values, that are set in the phone's system settings
44 changes: 44 additions & 0 deletions gears/compose/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# compose-ktx <GitHub path="RedMadRobot/redmadrobot-android-ktx/tree/main/compose-ktx"/>
[![Version](https://img.shields.io/maven-central/v/com.redmadrobot.extensions/compose-ktx?style=flat-square)][mavenCentral]
[![License](https://img.shields.io/github/license/RedMadRobot/redmadrobot-android-ktx?style=flat-square)][license]

---
<!-- START doctoc generated TOC please keep comment here to allow auto update -->
<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

- [Installation](#installation)
- [Usage](#usage)
- [Contributing](#contributing)

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

A set of gears for compose.

## Installation

Add the dependency:
```groovy
repositories {
mavenCentral()
google()
}
dependencies {
implementation("com.redmadrobot.gears:compose:<version>")
}
```

## Usage

| Gear | Description |
|:--------------------|:-----------|
| `FixedFontScaleContainer` | A container that fixes the font scale, ignoring values, that are set in the phone's system settings |

## Contributing

Merge requests are welcome.
For major changes, please open an issue first to discuss what you would like to change.


[mavenCentral]: https://search.maven.org/artifact/com.redmadrobot.extensions/compose-ktx
[license]: ../LICENSE
29 changes: 29 additions & 0 deletions gears/compose/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
plugins {
id("com.redmadrobot.android-library")
id("com.redmadrobot.publish")
convention.library.android
}

version = "1.6.6-0"
description = "A set of gears for compose"

redmadrobot {
android.minSdk = 21
}

android {
namespace = "$group.compose"

buildFeatures {
compose = true
}

composeOptions {
kotlinCompilerExtensionVersion = androidx.versions.compose.compiler.get()
}
}

dependencies {
api(androidx.compose.ui)
api(androidx.compose.runtime)
}
43 changes: 43 additions & 0 deletions gears/compose/src/main/kotlin/FixedFontScaleContainer.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.redmadrobot.extensions.compose

import androidx.compose.runtime.Composable
import androidx.compose.runtime.CompositionLocalProvider
import androidx.compose.ui.platform.LocalDensity
import androidx.compose.ui.unit.Density

/**
* A container that fixes the font scale, ignoring values,
* that are set in the phone's system settings
*/
@Composable
public fun FixedFontScaleContainer(
content: @Composable () -> Unit,
) {
val fixedFontScaleDensity = Density(LocalDensity.current.density)
CompositionLocalProvider(
LocalDensity provides fixedFontScaleDensity,
content = content,
)
}

/**
* A container that restricts the font scale, ignoring values,
* that are set in the phone's system settings
*
* @param limit - the upper limit of font enlargement
*/
@Composable
public fun LimitedFontScaleContainer(
limit: Float,
content: @Composable () -> Unit,
) {
val fontScale = LocalDensity.current.fontScale.coerceAtMost(limit)
val fixedFontScaleDensity = Density(
density = LocalDensity.current.density,
fontScale = fontScale,
)
CompositionLocalProvider(
LocalDensity provides fixedFontScaleDensity,
content = content,
)
}
1 change: 1 addition & 0 deletions gears/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
group=com.redmadrobot.gears
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ include(
":ktx:lifecycle-livedata-ktx",
":ktx:resources-ktx",
":ktx:viewbinding-ktx",
":gears:compose",
)

0 comments on commit 25bae5f

Please sign in to comment.