Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Compose Multiplatform] apply theme to contributors screen (w/ workaround) #1108

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package io.github.droidkaigi.confsched2023.contributors
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.ui.interop.LocalUIViewController
import androidx.compose.ui.window.ComposeUIViewController
import io.github.droidkaigi.confsched2023.designsystem.theme.KaigiTheme
import io.github.droidkaigi.confsched2023.model.ContributorsRepository
import io.github.droidkaigi.confsched2023.ui.UserMessageStateHolderImpl
import platform.UIKit.UIViewController
Expand All @@ -23,10 +24,12 @@ fun contributorViewController(
// viewModel.viewModelScope.cancel()
}

ContributorsScreen(
viewModel = viewModel,
isTopAppBarHidden = true,
onNavigationIconClick = { /** no action for iOS side **/ },
onContributorItemClick = onContributorItemClick,
)
KaigiTheme {
ContributorsScreen(
viewModel = viewModel,
isTopAppBarHidden = true,
onNavigationIconClick = { /** no action for iOS side **/ },
onContributorItemClick = onContributorItemClick,
)
}
}
Loading