Created
October 4, 2023 04:50
-
-
Save Mohammed-Alhams/fbae2880441bf14dc882e568f02b1208 to your computer and use it in GitHub Desktop.
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
// Screen Template | |
package ${PACKAGE_NAME} | |
import androidx.compose.runtime.Composable | |
import androidx.navigation.NavController | |
@Composable | |
fun ${NAME}Screen( | |
${NAME}State: ${NAME}UIState, | |
listener: ${NAME}ScreenInteractionListener, | |
navController: NavController | |
){ | |
} | |
//My_Class_name //this will be filled while using the template | |
//Class_name //using this variable, | |
//you can use the filled variable inside the template | |
#set( $Class_name = $My_Class_name ) | |
class $Class_name | |
// End Screen Template | |
// ViewModel Template | |
package ${PACKAGE_NAME} | |
import androidx.lifecycle.SavedStateHandle | |
import androidx.lifecycle.ViewModel | |
import kotlinx.coroutines.flow.MutableStateFlow | |
import kotlinx.coroutines.flow.MutableSharedFlow | |
import kotlinx.coroutines.flow.asSharedFlow | |
import kotlinx.coroutines.flow.asStateFlow | |
class ${NAME}ViewModel( | |
savedStateHandle: SavedStateHandle | |
): ViewModel(), ${NAME}ScreenInteractionListener{ | |
private val _uiState = MutableStateFlow(${NAME}UIState()) | |
val uiState = _uiState.asStateFlow() | |
private val _uiEffect = MutableSharedFlow<${NAME}UIEffect>() | |
val uiEffect = _uiEffect.asSharedFlow() | |
private val args: ${NAME}Args = ${NAME}Args(savedStateHandle) | |
} | |
// End ViewModel Template | |
// Route Template | |
package ${PACKAGE_NAME} | |
import android.annotation.SuppressLint | |
import androidx.compose.runtime.Composable | |
import androidx.lifecycle.SavedStateHandle | |
import androidx.lifecycle.compose.collectAsStateWithLifecycle | |
import androidx.navigation.NavController | |
import androidx.navigation.NavGraphBuilder | |
import androidx.navigation.compose.composable | |
import androidx.hilt.navigation.compose.hiltViewModel | |
private const val ROUTE = "${NAME}Screen" | |
fun NavController.navigateTo${NAME}(){ | |
navigate(ROUTE) | |
} | |
@SuppressLint("ComposableDestinationInComposeScope") | |
@Composable | |
fun NavGraphBuilder.${NAME}ScreenRoute( | |
navController: NavController, | |
viewModel: ${NAME}ViewModel = hiltViewModel() | |
){ | |
composable( | |
route = ROUTE, | |
// arguments = listOf(navArgument("exampleArg") { NavType.IntType }), | |
) { | |
val state = viewModel.uiState.collectAsStateWithLifecycle() | |
${NAME}Screen(state.value, viewModel, navController) | |
} | |
} | |
internal class ${NAME}Args() { | |
constructor(savedStateHandle: SavedStateHandle) : | |
this(/*checkNotNull(savedStateHandle[conversationIdArg]) as String*/) | |
companion object{ | |
//const val argName = "exampleArg" | |
} | |
} | |
// End Route Template | |
// Screen UI effect | |
package ${PACKAGE_NAME} | |
sealed interface ${NAME}UIEffect{ | |
} | |
// End Screen UI effect | |
// Screen UI Interaction listener | |
package ${PACKAGE_NAME} | |
interface ${NAME}ScreenInteractionListener | |
// End Screen UI Interaction listener | |
// Screen UI State | |
package ${PACKAGE_NAME} | |
data class ${NAME}UIState( | |
val state: String = "" | |
) | |
// Screen UI State | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment