When the currentManzil is updated from the ActionBar the filename is also updated but PdfView composable is not recall which uses the filename. Because here in my code the currentManzil is updated from the ActionBar and when the currentManzil updated it automatically updated the filename but when the filename updated i want to recall the PdfView composable or i want recomposition which updated my UI according to new data.
Here is my code below :
@Composable
fun ShowPdfScreen(manzil: Int, navController: NavController) {
var currentPage by remember { mutableIntStateOf(0) }
var totalPages by remember { mutableIntStateOf(0) }
var isFullScreen by remember { mutableStateOf(false) }
var currentManzil by remember { mutableIntStateOf(manzil) }
var fileName by remember { mutableStateOf("") }
// Hide the status bar
val systemUiController = rememberSystemUiController()
systemUiController.isStatusBarVisible = !isFullScreen
fileName = getFileName(currentManzil)
Log.d("Check Pdf", "filename is -> $fileName")
Scaffold(
topBar = {
if (!isFullScreen) {
ActionBar(title = currentManzil, true, navController) {
currentManzil = it
}
}
},
content = { paddingValues ->
Box(modifier = Modifier.padding(paddingValues)) {
Log.d("Check Pdf", "filename before pdfview -> $fileName")
PdfView(fileName = fileName, onPageChanged = { page, pageCount ->
currentPage = page
totalPages = pageCount
})
Log.d("Check Pdf", "PdfView called!")
}
},
floatingActionButton = {
SmallFloatingActionButton(
onClick = { isFullScreen = !isFullScreen },
containerColor = AppGreenColor,
contentColor = Color.White,
modifier = Modifier.size(50.dp)
) {
Icon(
painter = if (!isFullScreen) painterResource(id = R.drawable.fullscreen) else painterResource(
id = R.drawable.exit_fullscreen
),
contentDescription = "Switching Screens",
modifier = Modifier.padding(8.dp)
)
}
},
bottomBar = {
if (!isFullScreen) {
Box(
modifier = Modifier
.fillMaxWidth()
.height(30.dp)
.background(colorResource(id = R.color.app_green)),
contentAlignment = Alignment.Center
) {
Text(
text = "$currentPage / $totalPages",
fontSize = 16.sp,
color = Color.White,
fontWeight = FontWeight.Bold,
modifier = Modifier.align(Alignment.Center)
)
}
}
}
)
}
fun getFileName(manzil: Int): String {
Log.d("Check Pdf", "getFileName: called!")
when (manzil) {
R.string.first_manzil -> {
return "first_manzil.pdf"
}
R.string.second_manzil -> {
return "second_manzil.pdf"
}
R.string.third_manzil -> {
return "third_manzil.pdf"
}
R.string.fourth_manzil -> {
return "forth_manzil.pdf"
}
R.string.fifth_manzil -> {
return "fifth_manzil.pdf"
}
R.string.sixth_manzil -> {
return "sixth_manzil.pdf"
}
R.string.seventh_manzil -> {
return "seventh_manzil.pdf"
}
else -> {
return "Intro.pdf"
}
}
}
I want to update the UI or recall the PdfView composable when the filename changes.
Muhammad Umair Rasheed is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.