-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
15 changes: 7 additions & 8 deletions
15
composeApp/src/commonMain/kotlin/com/app/academy/HomeScreen.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,21 +1,20 @@ | ||
package com.app.academy | ||
|
||
import androidx.compose.foundation.layout.Box | ||
import androidx.compose.foundation.layout.fillMaxSize | ||
import androidx.compose.material.Text | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Alignment | ||
import androidx.compose.ui.Modifier | ||
import app.architect.notes.model.dummyNotes | ||
import cafe.adriel.voyager.core.screen.Screen | ||
import com.app.academy.components.NoteItems | ||
|
||
object HomeScreen : Screen { | ||
@Composable | ||
override fun Content() { | ||
Box( | ||
modifier = Modifier.fillMaxSize(), | ||
contentAlignment = Alignment.Center | ||
) { | ||
Text(text = "To be built") | ||
LazyColumn(Modifier.fillMaxSize()) { | ||
NoteItems(dummyNotes, onClick = {}) { | ||
//onDismissed | ||
} | ||
} | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
composeApp/src/commonMain/kotlin/com/app/academy/components/NoteItems.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.app.academy.components | ||
|
||
import androidx.compose.foundation.ExperimentalFoundationApi | ||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyListScope | ||
import androidx.compose.foundation.lazy.items | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.unit.dp | ||
import app.architect.notes.model.Note | ||
|
||
@OptIn(ExperimentalFoundationApi::class) | ||
fun LazyListScope.NoteItems( | ||
notes: List<Note>, | ||
onClick: (Note) -> Unit, | ||
onDismissed: (Note) -> Unit | ||
) { | ||
items(items = notes, key = { it.id }) { | ||
SwipeableNoteListCard( | ||
modifier = Modifier | ||
.fillMaxWidth() | ||
.padding(vertical = 8.dp, horizontal = 16.dp) | ||
.animateItemPlacement(), | ||
savedNote = it, | ||
onClick = { onClick(it) }, | ||
onDismissed = { onDismissed(it) } | ||
) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
composeApp/src/commonMain/kotlin/com/app/academy/components/NoteListCard.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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.app.academy.components | ||
|
||
import androidx.compose.foundation.layout.Arrangement | ||
import androidx.compose.foundation.layout.Column | ||
import androidx.compose.foundation.layout.padding | ||
import androidx.compose.foundation.lazy.LazyColumn | ||
import androidx.compose.foundation.lazy.LazyRow | ||
import androidx.compose.material.Card | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.MaterialTheme | ||
import androidx.compose.material.Text | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.Modifier | ||
import androidx.compose.ui.text.font.FontWeight | ||
import androidx.compose.ui.text.style.TextOverflow | ||
import androidx.compose.ui.unit.dp | ||
import app.architect.notes.model.Note | ||
|
||
/** | ||
* A composable that displays the information of a [Note], in a card. Some of the contents | ||
* might get truncated if the content of the [Note] is too long. Mainly meant to be used in | ||
* a list, such as a [LazyColumn] or a [LazyRow]. | ||
* | ||
* @param modifier The modifier to be applied to the card. | ||
* @param savedNote The note to be displayed. | ||
* @param onClick The click listener for the card. | ||
*/ | ||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun NoteListCard( | ||
modifier: Modifier = Modifier, | ||
savedNote: Note, | ||
onClick: () -> Unit | ||
) { | ||
Card(modifier = modifier, onClick = onClick) { | ||
Column( | ||
modifier = Modifier.padding(16.dp), | ||
verticalArrangement = Arrangement.spacedBy(8.dp) | ||
) { | ||
Text( | ||
text = savedNote.title, | ||
style = MaterialTheme.typography.h6, | ||
fontWeight = FontWeight.Bold, | ||
maxLines = 3 | ||
) | ||
Text( | ||
text = savedNote.content, | ||
maxLines = 3, | ||
minLines = 3, | ||
overflow = TextOverflow.Ellipsis | ||
) | ||
} | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
composeApp/src/commonMain/kotlin/com/app/academy/components/SwipeableNoteListCard.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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.app.academy.components | ||
|
||
import androidx.compose.foundation.layout.fillMaxWidth | ||
import androidx.compose.material.DismissDirection | ||
import androidx.compose.material.DismissState | ||
import androidx.compose.material.DismissValue | ||
import androidx.compose.material.ExperimentalMaterialApi | ||
import androidx.compose.material.SwipeToDismiss | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.remember | ||
import androidx.compose.ui.Modifier | ||
import app.architect.notes.model.Note | ||
|
||
@OptIn(ExperimentalMaterialApi::class) | ||
@Composable | ||
fun SwipeableNoteListCard( | ||
modifier: Modifier = Modifier, | ||
onClick: () -> Unit, | ||
onDismissed: () -> Unit, | ||
savedNote: Note, | ||
) { | ||
val dismissState = remember(savedNote) { | ||
DismissState( | ||
initialValue = DismissValue.Default, | ||
confirmStateChange = { | ||
if (it != DismissValue.DismissedToStart) return@DismissState false | ||
onDismissed() | ||
true | ||
} | ||
) | ||
} | ||
|
||
SwipeToDismiss( | ||
modifier = modifier, | ||
state = dismissState, | ||
background = {}, | ||
dismissContent = { | ||
NoteListCard( | ||
modifier = Modifier.fillMaxWidth(), | ||
savedNote = savedNote, | ||
onClick = onClick | ||
) | ||
}, | ||
directions = setOf(DismissDirection.EndToStart) | ||
) | ||
} |
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