Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/bottomnavapp/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
115 changes: 115 additions & 0 deletions example/bottomnavapp/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@

import Dependencies.Common.JAVA_TARGET
import Dependencies.Common.JAVA_VERSION

plugins {
id("com.android.application")
kotlin(Dependencies.Plugins.ANDROID)
}

android {
namespace = "com.rootstrap.example.bottomnavapp"

with(Dependencies.ConfigData) {
compileSdk = COMPILE_SDK_VERSION
buildToolsVersion = BUILD_TOOLS_VERSION

defaultConfig {
minSdk = MIN_SDK_VERSION
targetSdk = TARGET_SDK_VERSION
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
}

buildTypes {
getByName("release") {
isMinifyEnabled = false
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
)
}
}

compileOptions {
sourceCompatibility = JAVA_VERSION
targetCompatibility = JAVA_VERSION
}

kotlinOptions {
jvmTarget = JAVA_TARGET
/**
* Compose-metrics
* How to execute:
* ./gradlew assembleRelease -PcomposeCompilerReports=true
* Review reports in: app/build/compose_metrics
* */
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:metricsDestination=" + project.buildDir.absolutePath + "/compose_metrics"
)
freeCompilerArgs += listOf(
"-P",
"plugin:androidx.compose.compiler.plugins.kotlin:reportsDestination=" + project.buildDir.absolutePath + "/compose_metrics"
)
}

buildFeatures {
compose = true
buildConfig = true
}

composeOptions {
kotlinCompilerExtensionVersion = Dependencies.Versions.COMPOSE_COMPILER
}
}

dependencies {
implementation(project(":core:di"))
implementation(project(":core:domain"))
implementation(project(":example:core:domain"))
implementation(project(":example:core:usecases"))

with(Dependencies.Android) {
implementation(CORE)
implementation(APP_COMPAT)
implementation(LIFECYCLE_KTX)
implementation(LIFECYCLE_COMPOSE)
implementation(NAVIGATION_UI_RUNTIME)
implementation(SPLASH_SCREEN)
implementation(WINDOW)
}
with(Dependencies.Compose) {
implementation(ACTIVITY)
implementation(UI)
implementation(UI_TOOLING_PREVIEW)
implementation(MATERIAL3)
implementation(ICONS_EXTENDED)
implementation(NAVIGATION_COMPOSE)
implementation(LIFECYCLE_RUNTIME)
debugImplementation(UI_TOOLING)
}
with(Dependencies.Koin) {
implementation(CORE)
implementation(ANDROID)
implementation(ANDROID_NAVIGATION)
implementation(ANDROID_COMPAT)
implementation(WORK_MANAGER)
implementation(COMPOSE)
}
implementation(Dependencies.Rootstrap.FLOW_FORMS)

with(Dependencies.Test) {
testImplementation(MOCKK)
testImplementation(JUNIT)
testImplementation(KOIN_TEST)
testImplementation(KOIN_TEST_JUNIT)
testImplementation(COROUTINES_TEST)
}
with(Dependencies.AndroidTest) {
androidTestImplementation(EXT_JUNIT)
androidTestImplementation(ESPRESSO_CORE)
androidTestImplementation(COMPOSE_JUNIT)
debugImplementation(COMPOSE_MANIFEST)
}
}
21 changes: 21 additions & 0 deletions example/bottomnavapp/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.rootstrap.example.app.bottomnavapp

import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.ext.junit.runners.AndroidJUnit4

import org.junit.Test
import org.junit.runner.RunWith

import org.junit.Assert.*

/**
* Instrumented test, which will execute on an Android device.
*
* See [testing documentation](http://d.android.com/tools/testing).
*/
@RunWith(AndroidJUnit4::class)
class ExampleInstrumentedTest {
@Test
fun useAppContext() {
// Context of the app under test.
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
assertEquals("com.rootstrap.example.app.bottomnavapp", appContext.packageName)
}
}
24 changes: 24 additions & 0 deletions example/bottomnavapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android">

<application
android:name="com.rootstrap.App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AndroidComposeBase">
<activity
android:name="com.rootstrap.bottomnavapp.ui.MainActivity"
android:exported="true"
android:theme="@style/Theme.AndroidComposeBase">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>

</manifest>
13 changes: 13 additions & 0 deletions example/bottomnavapp/src/main/java/com/rootstrap/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.rootstrap

import android.app.Application
import com.rootstrap.di.appModule
import com.rootstrap.di.initDI

class App : Application() {

override fun onCreate() {
super.onCreate()
initDI(appModule = appModule)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.rootstrap.bottomnavapp.ui

import android.os.Bundle
import androidx.activity.ComponentActivity
import androidx.activity.compose.setContent
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.fillMaxSize
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.material3.BottomAppBar
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Scaffold
import androidx.compose.material3.Surface
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.clip
import androidx.compose.ui.unit.dp
import com.rootstrap.bottomnavapp.ui.base.navigation.BottomBarNavigation
import com.rootstrap.bottomnavapp.ui.base.navigation.BottomBarRow
import com.rootstrap.bottomnavapp.ui.base.navigation.rememberAppState
import com.rootstrap.bottomnavapp.ui.theme.ArticlesRepositoryTheme

class MainActivity : ComponentActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContent {
ArticlesRepositoryTheme {
val appState = rememberAppState()
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
Scaffold(
bottomBar = {
if (appState.shouldShowBottomBar)
BottomAppBar(
containerColor = MaterialTheme.colorScheme.primary,
contentPadding = PaddingValues(horizontal = 20.dp),
modifier = Modifier
.height(70.dp)
.clip(
RoundedCornerShape(
topStart = 24.dp, topEnd = 24.dp
)
)
) {
BottomBarRow(
navHostController = appState.navHostController,
)
}
}
) { innerPadding ->
BottomBarNavigation(
navHostController = appState.navHostController,
padding = innerPadding,
this
)
}
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.rootstrap.bottomnavapp.ui.base.navigation

import androidx.compose.runtime.Composable
import androidx.compose.runtime.Stable
import androidx.compose.runtime.remember
import androidx.navigation.NavHostController
import androidx.navigation.compose.currentBackStackEntryAsState
import androidx.navigation.compose.rememberNavController

@Composable
fun rememberAppState(
navHostController: NavHostController = rememberNavController()
) = remember(navHostController) {
AppState(navHostController)
}

@Stable
class AppState(
val navHostController: NavHostController
) {

private val routes = BottomBarRoutes.entries.map { it.routes }

val shouldShowBottomBar: Boolean
@Composable get() =
navHostController.currentBackStackEntryAsState().value?.destination?.route in routes
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.rootstrap.bottomnavapp.ui.base.navigation

import android.app.Activity
import androidx.compose.foundation.layout.PaddingValues
import androidx.compose.foundation.layout.padding
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.navigation.NavHostController
import androidx.navigation.compose.NavHost
import androidx.navigation.compose.composable
import androidx.navigation.navigation
import com.rootstrap.bottomnavapp.ui.pages.DetailScreen
import com.rootstrap.bottomnavapp.ui.pages.HomeScreen
import com.rootstrap.bottomnavapp.ui.pages.NotificationScreen
import com.rootstrap.bottomnavapp.ui.pages.ProfileScreen
import com.rootstrap.bottomnavapp.ui.pages.SplashScreen

@Composable
fun BottomBarNavigation(
navHostController: NavHostController,
padding: PaddingValues,
context: Activity
) {

NavHost(
navController = navHostController, startDestination = ScreenRoutes.Splash.route,
modifier = Modifier.padding(padding)
) {
composable(ScreenRoutes.Splash.route) {
SplashScreen(navHostController = navHostController)
}
navigation(
route = ScreenRoutes.BottomBar.route,
startDestination = BottomBarRoutes.HOME.routes
) {
composable(BottomBarRoutes.HOME.routes) {
HomeScreen(navHostController = navHostController,context)
}
composable(BottomBarRoutes.NOTIFICATION.routes) {
NotificationScreen(navHostController = navHostController)
}
composable(BottomBarRoutes.PROFILE.routes) {
ProfileScreen(navHostController = navHostController)
}
}
composable(ScreenRoutes.Detail.route) {
DetailScreen(navHostController = navHostController)
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.rootstrap.bottomnavapp.ui.base.navigation

import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import com.rootstrap.example.bottomnavapp.R

private const val HOME_ROUTE = "/home"
private const val NOTIFICATION_ROUTE = "/notification"
private const val PROFILE_ROUTE = "/profile"

enum class BottomBarRoutes(
val id: Int,
@StringRes val title: Int,
val routes: String,
@DrawableRes val icon: Int
) {

HOME(1, R.string.home, HOME_ROUTE, R.drawable.home),
NOTIFICATION(2, R.string.notification, NOTIFICATION_ROUTE, R.drawable.notification),
PROFILE(3, R.string.profile, PROFILE_ROUTE, R.drawable.profile)

}
Loading