Skip to content

Commit

Permalink
add preview for composable (#20)
Browse files Browse the repository at this point in the history
* add utils file

* add function to show picker and make it more simple

* add function to show picker

* add library files

* add library files

* build lib

* Update README.md

Signed-off-by: mohammed Elsdody <31186483+mohamedma872@users.noreply.github.com>

* add some file to gradle

* add maven publish

* add some updates to maven and gradle

* add library as project to main app

* add MavenPublication to lib

* update groupId , artifactId

* update groupId , artifactId

* update gradle

* Merge remote-tracking branch 'origin/Development' into Development

* stable release

* Update README.md

Signed-off-by: mohammed Elsdody <31186483+mohamedma872@users.noreply.github.com>

* Update README.md

Signed-off-by: mohammed Elsdody <31186483+mohamedma872@users.noreply.github.com>

* add preview  for each function

---------

Signed-off-by: mohammed Elsdody <31186483+mohamedma872@users.noreply.github.com>
  • Loading branch information
mohamedma872 authored Sep 8, 2024
1 parent 184083e commit fa830f9
Show file tree
Hide file tree
Showing 8 changed files with 109 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -38,3 +39,13 @@ fun FooterSection(nextMonthName: String, onConfirm: () -> Unit, onCancel: () ->
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewFooterSection() {
FooterSection(
nextMonthName = "Safar",
onConfirm = { /* Handle confirm action in preview */ },
onCancel = { /* Handle cancel action in preview */ }
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.Composable
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -44,3 +45,19 @@ fun HeaderSection(calendar: Calendar, onYearClick: () -> Unit) {
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHeaderSection() {
// Creating an instance of IslamicCalendar for preview purposes
val calendar = IslamicCalendar().apply {
set(Calendar.YEAR, 1445)
set(Calendar.MONTH, 1) // Safar
set(Calendar.DAY_OF_MONTH, 5)
}

// Preview the HeaderSection with a mock IslamicCalendar and a simple onYearClick action
HeaderSection(calendar = calendar, onYearClick = {
// Handle year click in preview
})
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -85,4 +86,11 @@ fun HijriDatePickerButton(
"umalqura" // "umalqura", "civil", or "islamic"
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePickerButton() {
// Preview the HijriDatePickerButton with "umalqura" as calendar type
HijriDatePickerButton(calendarType = "umalqura")
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog

Expand Down Expand Up @@ -107,3 +108,22 @@ fun HijriDatePickerDialogWithThreeSections(
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePickerDialogWithThreeSections() {
HijriDatePickerDialogWithThreeSections(
initialYear = 1445, // Initial Hijri year
initialMonth = 1, // Safar (month index starts at 0)
initialDay = 5, // 5th day of Safar
onDateSelected = { year, month, day ->
// Handle date selection (preview action)
},
onConfirm = {
// Handle confirm action (preview action)
},
onDismissRequest = {
// Handle dismiss action (preview action)
},
calendarType = "umalqura" // Simulate the "umalqura" calendar type for preview
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -79,4 +80,18 @@ fun MonthGridWithDays(
}
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewMonthGridWithDays() {
MonthGridWithDays(
selectedYear = 1445, // Example year
onDaySelected = { year, month, day ->
// Handle day selection (preview action)
},
preselectedMonth = 1, // Safar (0-indexed month)
preselectedDay = 5, // Preselected day
calendarType = "umalqura" // Calendar type for preview
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp

Expand Down Expand Up @@ -57,4 +58,16 @@ fun YearSelectionScreen(
)
}
}
}

@Preview(showBackground = true)
@Composable
fun PreviewYearSelectionScreen() {
YearSelectionScreen(
selectedYear = 1445, // Preselected year
onYearSelected = { year ->
// Handle year selection (preview action)
},
currentYear = 1445 // Scroll to this year by default
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.runtime.setValue
import androidx.compose.ui.tooling.preview.Preview

// Example of how you can trigger the date picker from anywhere
/* showHijriDatePicker(
Expand Down Expand Up @@ -70,3 +71,24 @@ fun showHijriDatePicker(
)
}
}

@Preview(showBackground = true)
@Composable
fun PreviewHijriDatePicker() {
// Preview the Hijri Date Picker with some predefined values
showHijriDatePicker(
initialYear = 1445, // Initial year in Hijri calendar
initialMonth = 1, // Safar (0-indexed month)
initialDay = 1, // 1st day of Safar
onDateSelected = { year, month, day ->
// Handle date selection (preview action)
},
onConfirm = { year, month, day ->
// Handle confirmation (preview action)
},
onDismissRequest = {
// Handle dismissal (preview action)
},
calendarType = "umalqura" // Calendar type for preview
)
}
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,3 +225,6 @@ For any questions or support regarding this project, you can contact the project

[![](https://jitpack.io/v/mohamedma872/HijriDatePickerPlus.svg)](https://jitpack.io/#mohamedma872/HijriDatePickerPlus)

---

This updated README includes the mention of the `getIslamicCalendar` function and an example of how to use it to get the current Hijri date. Let me know if you need any further adjustments!

0 comments on commit fa830f9

Please sign in to comment.