Skip to content

Commit

Permalink
Adjusting colors based on dark theme condition
Browse files Browse the repository at this point in the history
  • Loading branch information
retifrav committed Feb 8, 2024
1 parent f455a2f commit 0997203
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions android/app/src/main/java/com/example/some/MainActivity.kt
Expand Up @@ -6,6 +6,7 @@ import android.util.Log
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.Image
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.foundation.layout.Column
import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.Spacer
Expand Down Expand Up @@ -51,13 +52,16 @@ class MainActivity : ComponentActivity()
super.onCreate(savedInstanceState)
setContent {
SomeTheme {
// a surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
)
{
GrilsGallery(Grils.grilsData, this::doThingy)
GrilsGallery(
isSystemInDarkTheme(),
Grils.grilsData,
this::doThingy
)
}
}
}
Expand Down Expand Up @@ -103,7 +107,11 @@ fun GrilCard(gril: Gril)

@OptIn(ExperimentalMaterial3Api::class) // is there a fucking stable alternative?
@Composable
fun GrilsGallery(grils: List<Gril>, doSomething: () -> String) // can also be () -> Unit, if it's a function without return value
fun GrilsGallery(
darkTheme: Boolean,
grils: List<Gril>,
doSomething: () -> String // can also be () -> Unit, if it's a function without return value
)
{
Scaffold(
topBar = {
Expand All @@ -119,7 +127,10 @@ fun GrilsGallery(grils: List<Gril>, doSomething: () -> String) // can also be ()
)
},
colors = topAppBarColors(
containerColor = MaterialTheme.colorScheme.primary
containerColor = (
if (darkTheme) MaterialTheme.colorScheme.surfaceVariant
else MaterialTheme.colorScheme.surfaceTint
)
)
)
},
Expand Down Expand Up @@ -166,7 +177,10 @@ fun GrilsGalleryPreview() {
// don't know how to pass doThingy() function here,
// but apparently there is no need for that,
// given that this is just a static preview
GrilsGallery(Grils.grilsData, { "some string, doesn't matter" })
//GrilsGallery(Grils.grilsData, { /* and here can be some function, which also doesn't matter */ })
GrilsGallery(
isSystemInDarkTheme(),
Grils.grilsData,
{ "some string, doesn't matter" }
)
}
}
2 changes: 1 addition & 1 deletion cpp/src/thingy.cpp
Expand Up @@ -7,7 +7,7 @@
namespace dpndnc
{
extern "C" JNIEXPORT jstring JNICALL
Java_com_example_some_MainActivity_doThingy(JNIEnv *env, jobject) // functions has to have this prefix
Java_com_example_some_MainActivity_doThingy(JNIEnv *env, jobject) // function has to have this prefix in order to be callable from Java side
{
std::stringstream someThing;
someThing << "a string from C++: " << thingyString;
Expand Down

0 comments on commit 0997203

Please sign in to comment.