-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apply theme to contributors screen with workaround
- Loading branch information
Showing
2 changed files
with
28 additions
and
30 deletions.
There are no files selected for viewing
43 changes: 19 additions & 24 deletions
43
.../src/iosMain/kotlin/io/github/droidkaigi/confsched2023/designsystem/theme/FontResource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,32 @@ | ||
package io.github.droidkaigi.confsched2023.designsystem.theme | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.getValue | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.runtime.setValue | ||
import androidx.compose.ui.text.font.FontFamily | ||
import androidx.compose.ui.text.platform.Font | ||
import org.jetbrains.compose.resources.ExperimentalResourceApi | ||
import org.jetbrains.compose.resources.resource | ||
|
||
val fontMap: HashMap<String, FontFamily?> = HashMap() | ||
|
||
// https://ishroid.medium.com/custom-font-loading-in-kmp-compose-multiplatform-2eb19865f61b | ||
@ExperimentalResourceApi | ||
@Composable | ||
actual fun fontFamilyResource(fontResource: FontResource): FontFamily? { | ||
var fontFamily: FontFamily? by | ||
remember(fontResource.resName) { mutableStateOf(fontMap[fontResource.resName]) } | ||
if (fontFamily == null) { | ||
LaunchedEffect(fontResource.resName) { | ||
fontFamily = try { | ||
val font = Font( | ||
fontResource.resName, | ||
resource("font/${fontResource.resName}").readBytes(), | ||
) | ||
fontMap[fontResource.resName] = FontFamily(font) | ||
fontMap[fontResource.resName] | ||
} catch (e: Exception) { | ||
throw IllegalArgumentException(e) | ||
} | ||
} | ||
} | ||
return fontFamily | ||
// FIXME: Load the custom font in resources directory | ||
return FontFamily.Default | ||
// var fontFamily: FontFamily? by | ||
// remember(fontResource.resName) { mutableStateOf(fontMap[fontResource.resName]) } | ||
// if (fontFamily == null) { | ||
// LaunchedEffect(fontResource.resName) { | ||
// fontFamily = try { | ||
// val font = Font( | ||
// fontResource.resName, | ||
// resource("font/${fontResource.resName}").readBytes(), | ||
// ) | ||
// fontMap[fontResource.resName] = FontFamily(font) | ||
// fontMap[fontResource.resName] | ||
// } catch (e: Exception) { | ||
// throw IllegalArgumentException(e) | ||
// } | ||
// } | ||
// } | ||
// return fontFamily | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters