### View Generation Example Source: https://github.com/useradgents/skot/blob/develop/docs/start/createcomponent.md Provides an example of a generated View class `MyComponentView`. It demonstrates implementing interface methods for handling value and variable updates, and its constructor. ```kotlin class MyComponentView( override val proxy: MyComponentViewProxy, activity: SKActivity, fragment: Fragment?, binding: AccountSimpleItemBinding, ) : SKComponentView(proxy, activity, fragment, binding), MyAccountRAI { override fun onValue(value: String?): Unit { // use your value } override fun onVariable(variable: String): Unit { // use your value } } ``` -------------------------------- ### ViewModel Generation Example Source: https://github.com/useradgents/skot/blob/develop/docs/start/createcomponent.md Illustrates the structure of a generated ViewModel class `MyComponent`, extending `MyComponentGen`. It shows how to initialize dependencies and the view, including passing initial values. ```kotlin class MyComponent : MyComponentGen() { override val otherComponent = MyOtherComponent() override val view: MyComponent = viewInjector.myComponent( visibilityListener = this, value = "MyValue", variableInitial = "MyVariable", otherComponent = otherComponent.view ) } ``` -------------------------------- ### Skot Starter Plugin Configuration (build.gradle.kts) Source: https://github.com/useradgents/skot/wiki/start/createproject Configures the Skot starter plugin for a new project. This file will be overridden after initialization. It requires the 'tech.skot.starter' plugin and defines the application package and name. ```kotlin buildscript { repositories { google() } } plugins { id("tech.skot.starter") version "1.+" } skot { appPackage = "your.package.name" appName = "Your app name" } ``` -------------------------------- ### Screen Implementation Example (Kotlin) Source: https://github.com/useradgents/skot/blob/develop/docs/architecture/modelcontract.md An example of a screen implementing its ModelContract. It sets up a button action that calls the model's doClickAction and observes subtitle data from the model to update the view. ```kotlin class MyScreen : MyScreenGen() { override val button = SKButton(strings.text) { launchWithLoaderAndError { model.doClickAction() } } override val loader = SKLoader() override val view: MyScreenVC = viewInjector.myScreen( visibilityListener = this, subtitleInitial = "", button = button.view, loader = loader.view ) init { model.subtitle.onData { view.subtitle = it } } } ``` -------------------------------- ### Initialize Skot Project with Gradle Source: https://context7.com/useradgents/skot/llms.txt Sets up a new Skot project by configuring the build.gradle.kts file with necessary plugins and parameters. It also includes terminal commands to generate the Gradle wrapper, start the project, and generate code. ```kotlin buildscript { repositories { google() } } plugins { id("tech.skot.starter") version "1.+" } skot { appPackage = "com.example.myapp" appName = "My App" } ``` ```bash gradle wrapper ./gradlew start ./gradlew skGenerate ``` -------------------------------- ### Implement Welcome Screen ViewModel Logic Source: https://context7.com/useradgents/skot/llms.txt Provides the implementation for the generated Welcome screen ViewModel. It initializes the view contract, sets the welcome text, and configures the start button's tap handler to navigate to the next screen. ```kotlin // Generated ViewModel - implement business logic package com.example.myapp.screens class WelcomeScreen : SKScreen() { override val view = WelcomeScreenVC.inject() init { view.welcomeText = "Welcome to Skot!" view.startButton = SKButton( label = "Get Started", onTap = { onStartButtonClicked() } ) } private fun onStartButtonClicked() { push(HomeScreen()) } } ``` -------------------------------- ### Add Skot Environment Tasks in build.gradle.kts Source: https://github.com/useradgents/skot/wiki/start/addenvironment Demonstrates how to add environment switching tasks for Prod, Preprod, and Rec environments within the Skot module's build.gradle.kts file. These tasks are managed by the skSwitchTask function. ```kotlin skSwitchTask("TaskEnvName", "dev") ``` -------------------------------- ### Bash Script for CI/CD Environment Update Source: https://github.com/useradgents/skot/wiki/start/addenvironment A bash script designed for CI/CD pipelines to automate the process of updating the environment and cleaning the project. It executes Gradle tasks to switch the environment and then cleans the build. ```bash #!/usr/bin/env bash ./gradlew yourChangeEnvTask ./gradlew clean ``` -------------------------------- ### Screen Model Implementation Example (Kotlin) Source: https://github.com/useradgents/skot/blob/develop/docs/architecture/modelcontract.md Implementation of the Screen's ModelContract. It handles the subtitle data using SKManualData and provides the logic for the doClickAction, updating the subtitle value. ```kotlin class MyScreenModel( override val coroutineContext: CoroutineContext) : MyScreenMC, CoroutineScope { override val subtitle = SKManualData() override suspend fun doClickAction(){ val subtitle = rootState.myModel.computeNewSubtitle() subtitle.value = subtitle } } ``` -------------------------------- ### Show Basic Alert Dialog with Buttons (Kotlin) Source: https://github.com/useradgents/skot/wiki/components/framework_components/skalert Example of using the `show` function of the SKAlert class to display a basic alert dialog. It includes a title, message, a main action button with a lambda for handling the action, and an optional secondary cancel button. ```kotlin alert.show( title = strings.account_screen_delete_account_alert_title, message = strings.account_screen_delete_account_alert_message, mainButton = SKAlertVC.Button( strings.account_screen_delete_account_alert_btn_delete ) { launchWithLoaderAndErrors { model.deleteAccount() snackBar.show(strings.account_screen_delete_account_success) } }, secondaryButton = SKAlertVC.Button( strings.generic_cancel ) ) ``` -------------------------------- ### Pass State from ViewModel in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/start/addstate.md This Kotlin code example shows how the state is passed from the ViewModel to the component. The `connectedState` property, declared as a dependency, is instantiated and passed during the component's initialization. ```kotlin class AccountScreen() { connectedState: ConnectedConfStateContract } : AccountScreenGen(connectedState) ``` -------------------------------- ### Show Customized Snackbar in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/sksnackbar This example shows how to display a Snackbar with advanced customization. It includes setting a styled message using `skSpannedString`, specifying the `position`, `background`, and adding a `rightIcon`. ```kotlin snackBar.show( message = skSpannedString { font(fonts.quicksand_bold) { append(strings.demat_notif_text_enabled) } }, position = SKSnackBarVC.Position.TopWithInsetPadding, background = colors.no_more_paper, rightIcon = icons.ic_img_plane_ok ) ``` -------------------------------- ### Define a State Interface (Kotlin) Source: https://github.com/useradgents/skot/wiki/start/addstate Defines a new state interface by extending SKStateDef. This example shows how to add properties like userId and token to the ConnectedStateDef. ```kotlin interface ConnectedStateDef : SKStateDef { val userId: String var token: Token } ``` -------------------------------- ### Declare and Instantiate SKSnackbar in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/sksnackbar This snippet demonstrates how to declare an SKSnackbarVC interface in a screen view controller and then instantiate it as an SKSnackBar object. This is the initial setup required before displaying any snackbar messages. ```kotlin interface MyAccountScreenVC : SKScreenVC, AccountActions { val snackBar: SKSnackBarVC } override val snackBar = SKSnackBar() ``` -------------------------------- ### Show Bottom Sheet Dialog in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/skbottomsheet This code illustrates how to display a bottom sheet dialog using the `show` function of an `SKBottomSheet` instance. It takes a `SKScreen` (represented here by `ModifyQuantityBottomSheet`), and optional boolean parameters `skipCollapsed` and `expanded` to control the behavior of the bottom sheet. The `skipCollapsed` parameter defaults to `false` and `expanded` defaults to `false` in this example, but they can be adjusted as needed. ```kotlin bottomSheet.show( ModifyQuantityBottomSheet( /* ... */), skipCollapsed = false, expanded = false ) ``` -------------------------------- ### Launch Screen with State (Kotlin) Source: https://github.com/useradgents/skot/wiki/start/addstate Demonstrates how to launch a screen, ensuring the required state is present before proceeding. If the state is not available, an alternative action or log message is executed. ```kotlin fun launchAccountScreen() { rootState.connectedState?.let { push(AccountScreen(it)) }?:run { SkLog.d("User not connected") } } ``` -------------------------------- ### Instantiate SKWebView with Configuration and Launch Option in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Instantiate the SKWebView component with custom configuration and a specific launch option. This allows for more control over the WebView's behavior and how the initial content is loaded. ```kotlin public override val webView: SKWebView = SKWebView( config = SKWebViewVC.Config("AndroidApp"), launch = SKWebViewVC.Launch.OpenUrl(url = "https://www.useradgents.com/") ) ``` -------------------------------- ### Instantiate and Configure SKList Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/sklist.md Demonstrates the instantiation of an SKList and the assignment of custom list items. SKList uses SKComponents for rendering items, and performance can be improved by overriding `computeItemId` and `onSwipe`. ```kotlin override val myList = SKList(name) init{ val listItems = listOf( MyComponentHeader("testHeader1"), MyComponent("test1"), MyComponent("test2"), MyComponentHeader("testHeader2"), MyComponent("test3"), MyComponent("test4"), MyComponent("test5") ) myList.items = listItems } ``` -------------------------------- ### Instantiate SKLoader in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skloader.md This code demonstrates how to instantiate an SKLoader component in Kotlin. It's typically done within a screen's implementation to provide the loader functionality. ```kotlin override val loader: SKLoader = SKLoader() ``` -------------------------------- ### Instantiate SKWebView with URL in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Instantiate the SKWebView component by providing a URL. This is a straightforward way to load a web page directly upon initialization. ```kotlin override val webView: SKWebView = SKWebView(url = "https://www.useradgents.com/") ``` -------------------------------- ### Kotlin Dependency Injection Configuration and Usage Source: https://context7.com/useradgents/skot/llms.txt Shows how to configure and utilize a dependency injection system in Kotlin using the SKOT framework. It covers defining services, creating modules with singletons and factories, initializing the injector, and retrieving dependencies within ViewModels and Components. ```kotlin import tech.skot.core.di.Module import tech.skot.core.di.module import tech.skot.core.di.get import tech.skot.core.di.injector // Define services interface ApiService { suspend fun fetchData(): String } class ApiServiceImpl : ApiService { override suspend fun fetchData() = "Data from API" } interface Logger { fun log(message: String) } class ConsoleLogger : Logger { override fun log(message: String) = println(message) } // Create module with dependencies val appModule = module { // Singleton - created once and reused single { ApiServiceImpl() } single { ConsoleLogger() } // Factory - new instance each time factory { UserRepository(get(), get()) } // Named dependency byName["apiKey"] = "sk_live_123456789" } // Initialize injector injector = BaseInjector(listOf(appModule)) // Load additional modules at runtime injector?.loadModules(listOf(featureModule)) // Retrieve dependencies class LoginViewModel { private val apiService: ApiService = get() private val logger: Logger = get() private val apiKey: String = getByName("apiKey") fun performLogin() { logger.log("Starting login") launch { val result = apiService.fetchData() logger.log("Login result: $result") } } } // Inject in components class MyComponent : SKComponent() { private val repository: UserRepository = get() init { launch { val data = repository.getUserData() view.displayData = data } } } ``` -------------------------------- ### Launch Coroutines with Loader and Error Handling in Kotlin Source: https://context7.com/useradgents/skot/llms.txt Demonstrates launching coroutines with built-in support for displaying loaders, handling errors, and customizing error treatments in Skot components. Useful for asynchronous operations where user feedback is crucial. ```kotlin import tech.skot.core.components.SKComponent import kotlinx.coroutines.delay class DashboardComponent : SKComponent() { init { // Standard coroutine launch launch { loadInitialData() } // Launch with loader (shows loading indicator) launchWithLoaderAndErrors { val data = fetchUserData() view.displayData = data } // Launch with options launchWithOptions( withLoader = true, errorMessage = "Failed to load dashboard", specificErrorTreatment = { ex -> displayCustomError(ex) } ) { val metrics = fetchMetrics() displayMetrics(metrics) } // Launch without crash (catches exceptions) launchNoCrash { while (true) { updateLiveData() delay(5000) } } // Observe reactive data userDataSource.onData( validity = 300000, withLoaderForFirstData = true, fallBackDataIfError = true ) { userData -> updateUI(userData) } } // Override for custom error handling override fun treatError(exception: Exception, errorMessage: String?) { logE(exception, errorMessage ?: "Unknown error") displayMessageError(errorMessage ?: "Something went wrong") } // Cleanup when component is removed override fun onRemove() { super.onRemove() // Cancels all coroutines closeResources() unsubscribeFromServices() } // Request permissions private fun accessCamera() { requestPermissions( permissions = listOf(SKPermission.CAMERA), onResult = { grantedPermissions -> if (grantedPermissions.isNotEmpty()) { openCamera() } else { displayMessageError("Camera permission denied") } } ) } // Simplified permission check private fun takePhoto() { doWithPermission( permission = SKPermission.CAMERA, onOk = { capturePhoto() }, onKo = { showPermissionExplanation() } ) } // Multiple permissions private fun recordVideo() { doWithPermissions( SKPermission.CAMERA, SKPermission.RECORD_AUDIO, onOk = { startRecording() }, onKo = { displayMessageError("Permissions required") } ) } // Display messages to user private fun showMessages() { displayMessageDebug("Debug info") displayMessageInfo("Information") displayMessageWarning("Warning") displayMessageError("Error occurred") } // Logging private fun performAction() { logD("Performing action with data: $data") try { riskyOperation() } catch (e: Exception) { logE(e, "Failed to perform action") } } } ``` -------------------------------- ### Define Welcome Screen View Contract Source: https://context7.com/useradgents/skot/llms.txt Defines the view contract for the Welcome screen, specifying UI elements like text and a button. It also marks the parent screen (SplashVC) to enable navigation using the @SKOpens annotation. ```kotlin package com.example.myapp.screens import tech.skot.core.components.SKScreenVC import tech.skot.core.components.inputs.SKButtonVC interface WelcomeScreenVC : SKScreenVC { var welcomeText: String var startButton: SKButtonVC } // Mark the parent screen to enable navigation @SKOpens([WelcomeScreenVC::class]) interface SplashVC : SKScreenVC { var splashText: String } ``` -------------------------------- ### Instantiate and Show SKBottomSheet (Kotlin) Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skbottomsheet.md Demonstrates how to instantiate the SKBottomSheet and display a custom bottom sheet dialog (ModifyQuantityBottomSheet). It includes parameters to control the initial state and collapsing behavior. ```kotlin override val bottomSheet: SKBottomSheet = SKBottomSheet() bottomSheet.show( ModifyQuantityBottomSheet( /* ... */), skipCollapsed = false, expanded = false ) ``` -------------------------------- ### SKStack Navigation Management in Kotlin Source: https://context7.com/useradgents/skot/llms.txt Demonstrates how to manage screen stacks and navigation flow using SKStack components in Kotlin. Covers pushing, replacing, popping screens, and custom stack management with transitions. Dependencies include SKRootStack, SKStack, and SKTransition. ```kotlin import tech.skot.core.components.SKRootStack import tech.skot.core.components.SKStack import tech.skot.core.view.SKTransition // Push screen to root stack class LoginScreen : SKScreen() { private fun onLoginSuccess() { SKRootStack.push(HomeScreen()) // or push(HomeScreen()) // Uses parent stack or root } } // Replace current screen class WelcomeScreen : SKScreen() { private fun skipToMain() { replaceWith(MainScreen()) } } // Pop current screen class ProfileScreen : SKScreen() { private fun goBack() { finish() // Removes self from stack } private fun goBackIfInStack() { finishIfInAStack() // Safe version, doesn't throw if not in stack } } // Remove all screens on top class CheckoutScreen : SKScreen() { private fun returnToProducts() { removeAllScreensOnTop() // Back to this screen, removing all above } } // Custom stack management val navigationStack = SKStack() navigationStack.content = HomeScreen() // Set initial screen // Push with custom transition navigationStack.push( screen = DetailScreen(itemId = "123"), transition = SKTransition.SlideLeft ) // Pop with callback navigationStack.pop( transition = SKTransition.Fade, ifRoot = { // Called if already at root, can't pop exitApp() } ) // Replace screen in stack navigationStack.replace( oldScreen = currentScreen, newScreen = updatedScreen, transition = SKTransition.SlideUp ) // Set default transitions navigationStack.defaultPushTransition = SKTransition.SlideLeft navigationStack.defaultPopTransition = SKTransition.SlideRight // Reset to root screen SKRootStack.resetToRoot() // Get current screen val topScreen = SKRootStack.screenOnTop // Kill all screens (exit app) kill() // Exit app properly (Android) exit() ``` -------------------------------- ### Create and Manage SKButton Component Source: https://context7.com/useradgents/skot/llms.txt Demonstrates the creation and management of SKButton components. It shows how to define basic buttons with tap handlers, dynamically update their state (enabled, label, hidden), and use them within view contracts. ```kotlin import tech.skot.core.components.inputs.SKButton // Basic button with tap handler val loginButton = SKButton( label = "Login", enabled = true, hidden = false, debounce = 500, // milliseconds between taps onTap = { performLogin() } ) // Dynamic button state management val submitButton = SKButton(label = "Submit") submitButton.enabled = formIsValid() submitButton.label = if (isLoading) "Submitting..." else "Submit" submitButton.hidden = !userIsAuthenticated() // View contract interface interface MyScreenVC : SKScreenVC { var loginButton: SKButtonVC } ``` -------------------------------- ### Launch Operation with Specific Loader in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skloader.md This Kotlin code demonstrates how to launch an operation using a specific, custom-named loader (`myOtherLoader`) instead of the default one. This allows for more granular control over loading indicators for different tasks. ```kotlin override val myOtherLoader: SKLoader = SKLoader() init { launchWithLoaderAndErrors(specificLoader = myOtherLoader) { /* Stuff */ } } ``` -------------------------------- ### Add Elements to SKComponentVC Interface Source: https://github.com/useradgents/skot/wiki/start/createcomponent Demonstrates adding necessary elements like dependencies, values, and functions to an `SKComponentVC` interface. It shows how to use `@SKUses` for dependencies and define properties and methods. ```kotlin @SKUses([MyOtherComponentVC::class]) interface MyComponentVC : SKComponentVC { val otherComponent : MyOtherComponentVC } ``` ```kotlin interface MyComponentVC : SKComponentVC { val value : String? } ``` ```kotlin interface MyComponentVC : SKComponentVC { val variable : String? } ``` ```kotlin interface MyComponentVC : SKComponentVC { fun myFunction(onFinish : () -> Unit) } ``` ```kotlin @SKUses([MyOtherComponentVC::class]) interface MyComponentVC : SKComponentVC { fun myFunction() val otherComponent : MyOtherComponentVC val value : String? var variable : String } ``` -------------------------------- ### Instantiate SKFrame in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skframe.md Instantiates a SKFrame component in Kotlin, providing a set of SKScreens to display and an initial screen. This code is used within your screen's implementation to set up the frame. ```kotlin override val frame = SKFrame(screens = setOf(buyingVouchersScreen), screenInitial = buyingVouchersScreen) ``` -------------------------------- ### Annotate Launching Screen for New Screen (Kotlin) Source: https://github.com/useradgents/skot/wiki/start/createscreen Adds an SKOpens annotation to an existing screen's view contract. This annotation specifies which new screen (identified by its view contract class) can be launched from this screen. It's crucial for defining navigation paths. ```kotlin @SKOpens([ScreenNameVC::class]) interface SplashVC : SkScreenVC { var welcomeText : String var btStartApp : SkButtonVC } ``` -------------------------------- ### SKWebViewVC.Launch Properties in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Defines the launch options for SKWebViewVC, including callbacks for page load completion, JavaScript execution upon finish, cookie management, and the initial URL to load. These options control the initial state and loading behavior of the WebView. ```kotlin sealed class Launch { data class OpenUrl(val url: String? = null, ...) data class OpenUrlWithHeader(val url: String? = null, val headers: Map = emptyMap(), ...) data class OpenPostUrl(val url: String? = null, val post: Map = emptyMap(), ...) data class LoadData(val data: String, ...) // Other Launch types and their properties val onFinished: ((title : String?) -> Unit)? val javascriptOnFinished: String? val removeCookies: Boolean val cookie: Pair? val url: String? } ``` -------------------------------- ### Basic ViewModel Initialization in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/architecture/viewmodel.md This snippet shows a basic implementation of a ViewModel in Kotlin. It initializes associated components like SkButton and MyOtherComponent and sets up the view contract with data from the model and constructor. ```kotlin class MyComponent(title : String): MyComponentGen() { val button = SkButton() val myOtherComponent = MyOtherComponent() override val view: MyComponentVC = viewInjector.myComponent( this, button = button.view, myOtherComponent = myOtherComponent.view, title = title, subtitleInitial = model.getSubtitle() ) } ``` -------------------------------- ### Define SKComponentVC Interface Source: https://github.com/useradgents/skot/wiki/start/createcomponent Creates a basic interface `MyComponentVC` that inherits from `SKComponentVC` in the `screens` folder of the `viewcontract` module. ```kotlin interface MyComponentVC : SKComponentVC { } ``` -------------------------------- ### SKWebViewVC.Launch.OpenUrl in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Represents launching a WebView by opening a specific URL, with default settings for callbacks and cookie management. This is a common option for displaying external web content. ```kotlin data class OpenUrl( val url: String? = null, private val onFinished: ((title : String?) -> Unit)? = null, private val javascriptOnFinished: String? = null, private val removeCookies: Boolean = false, val cookie: Pair? = null, val onError: (() -> Unit)? = null ) : Launch() ``` -------------------------------- ### Show SKPopupWindow with a Component Source: https://github.com/useradgents/skot/wiki/components/framework_components/skpopupwindow Call the show method on the popupWindow instance to display a SKComponent. This method takes the component to be shown and a behavior parameter that defines its dismissal behavior. ```kotlin popupWindow.show(MyComponent({popupWindow.dismiss()}),behavior) where behavior is one of : `SKWindowPopupVC.Cancelable(val onDismiss:(()->Unit)? = null)` : click outside of popup dismiss it `SKWindowPopupVC.NotCancelable` : click outside keep the popup open ``` -------------------------------- ### SKWebViewVC.Launch.LoadData in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Launches a WebView by loading raw data, such as HTML content, directly. This is useful for displaying locally generated or stored web content without needing a network request. It includes error handling and basic launch configurations. ```kotlin data class LoadData( val data: String, private val onFinished: ((title : String?) -> Unit)? = null, private val javascriptOnFinished: String? = null, private val removeCookies: Boolean = false, val cookie: Pair? = null, val onError: (() -> Unit)? = null ) : Launch() ``` -------------------------------- ### SKWebViewVC.Launch.OpenPostUrl in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Launches a WebView by sending a POST request to a specified URL with provided POST data. This is suitable for submitting form data or sending information to an API endpoint. It includes error handling and inherits core launch configurations. ```kotlin data class OpenPostUrl( val url: String? = null, val post: Map = emptyMap(), private val onFinished: ((title : String?) -> Unit)? = null, private val javascriptOnFinished: String? = null, private val removeCookies: Boolean = false, val cookie: Pair? = null, val onError: (() -> Unit)? = null ) : Launch() ``` -------------------------------- ### Define Screen View Contract Interface (Kotlin) Source: https://github.com/useradgents/skot/wiki/start/createscreen Defines the view contract for a screen by creating an interface that inherits from SKScreenVC. This interface declares UI elements and their properties. It serves as a blueprint for the screen's user interface and data binding. ```kotlin interface ScreenNameVC : SKScreenVC { var welcomeText : String var btStartApp : SkButtonVC } ``` -------------------------------- ### Generate ViewModel and View Source: https://github.com/useradgents/skot/wiki/start/createcomponent Details the Gradle task `skGenerate` for generating the ViewModel, View, and XML layout. It specifies naming conventions for the generated artifacts based on the ViewContract. ```kotlin class MyComponent : MyComponentGen() { override val otherComponent = MyOtherComponent() override val view: MyComponent = viewInjector.myComponent( visibilityListener = this, value = "MyValue", variableInitial = "MyVariable", otherComponent = otherComponent.view ) } ``` ```kotlin class MyComponentView( override val proxy: MyComponentViewProxy, activity: SKActivity, fragment: Fragment?, binding: AccountSimpleItemBinding, ) : SKComponentView(proxy, activity, fragment, binding), MyAccountRAI { override fun onValue(value: String?): Unit { // use your value } override fun onVariable(variable: String): Unit { // use your value } } ``` -------------------------------- ### Instantiate SKPager Component in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skpager.md Initializes an SKPager component with a list of screens, an initial selected page index, and swipe functionality. The 'initialScreens' parameter can be an empty list. ```kotlin import com.example.yourapp.skmodule.SKPager import com.example.yourapp.screens.PaymentSlideScreen override val pager = SKPager( initialScreens = listOf(PaymentSlideScreen(/*...*/), PaymentSlideScreen(/*Мне*/)), initialSelectedPageIndex = 0, swipable = true ) ``` -------------------------------- ### Create and Manage SKInput Component Source: https://context7.com/useradgents/skot/llms.txt Illustrates the usage of SKInput components for text input fields. It covers email and password input types, validation rules (regex, minSize), error handling, programmatic focus, cursor selection, and manual validation triggers. ```kotlin import tech.skot.core.components.inputs.SKInput import tech.skot.core.components.inputs.SKInputVC // Email input with validation val emailInput = SKInput( hint = "Enter your email", nullable = false, viewType = SKInputVC.Type.EMail, maxSize = 100, regex = Regex("^[A-Za-z0-9+_.-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}$"), defaultErrorMessage = "Invalid email format", onDone = { text -> // Called when user presses done/enter validateAndSubmit(text) } ) // Password input with visibility toggle val passwordInput = SKInput( hint = "Password", nullable = false, viewType = SKInputVC.Type.Password, minSize = 8, defaultErrorMessage = "Password must be at least 8 characters", showPassword = false ) // Check validity and get value if (emailInput.isValid) { val emailValue = emailInput.value // String? sendToServer(emailValue) } // Programmatic focus and cursor position emailInput.view.requestFocus() emailInput.view.getCursorSelection { (start, end) -> println("Selection: $start to $end") } // Manual validation trigger emailInput.updateValidy() // Shows error if invalid ``` -------------------------------- ### Instantiate SKList in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/sklist This snippet demonstrates how to instantiate an SKList object with a given name in Kotlin. This is a fundamental step for creating a list component. ```kotlin override val myList = SKList(name) ``` -------------------------------- ### Generate Skot Code Source: https://context7.com/useradgents/skot/llms.txt Command to execute after defining a view contract to automatically generate the corresponding ViewModel, View, and mock implementations for testing. ```bash ./gradlew skGenerate ``` -------------------------------- ### Add SKComponentVC with Dependencies Source: https://github.com/useradgents/skot/blob/develop/docs/start/createcomponent.md Extends the `MyComponentVC` interface to include a dependency on `MyOtherComponentVC` using the `@SKUses` annotation. It also declares a property `otherComponent` to access this dependency. ```kotlin @SKUses([MyOtherComponentVC::class]) interface MyComponentVC : SKComponentVC { val otherComponent : MyOtherComponentVC } ``` -------------------------------- ### Instantiate SKButton in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skbutton.md Demonstrates how to instantiate an SKButton in Kotlin, providing a name and an optional lambda for the onTap action. This allows for programmatic control over button behavior. ```kotlin override val myButtonId = SKButton(name) { //onTap } ``` -------------------------------- ### Bash Script for CI/CD Environment Update Source: https://github.com/useradgents/skot/blob/develop/docs/start/addvariant.md This bash script automates the process of updating the environment variant for CI/CD clients. It executes the Gradle task to change the environment and then runs a clean task to ensure the build reflects the new configuration. ```bash #!/usr/bin/env bash ./gradlew skot:yourChangeEnvTask ./gradlew clean ``` -------------------------------- ### XML Layout for Loader Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skloader.md This XML defines a layout to be used as a loader. It's a FrameLayout containing a ProgressBar and is initially set to GONE visibility, meant to be controlled by SKLoader. ```xml ``` -------------------------------- ### SKWebViewVC.Launch.OpenUrlWithHeader in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Launches a WebView by opening a URL with custom headers. This is useful for making authenticated requests or providing specific request metadata to the server. It inherits general launch properties but allows for header customization. ```kotlin data class OpenUrlWithHeader( val url: String? = null, val headers: Map = emptyMap(), private val onFinished: ((title : String?) -> Unit)? = null, private val javascriptOnFinished: String? = null, private val removeCookies: Boolean = false, val cookie: Pair? = null, val onError: (() -> Unit)? = null ) : Launch() ``` -------------------------------- ### Instantiate SKSnackBar Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/sksnackbar.md This Kotlin code demonstrates how to instantiate the SKSnackBar class within your screen implementation. This makes the Snackbar functionality available for use. ```kotlin override val snackBar = SKSnackBar() ``` -------------------------------- ### Show SKPopupWindow with a Component and Behavior Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skpopupwindow.md Display the SKPopupWindow by calling its show method with a specific SKComponent and a behavior. The behavior dictates whether the popup can be dismissed by clicking outside. ```kotlin popupWindow.show(MyComponent({popupWindow.dismiss()}),behavior) ``` -------------------------------- ### SKWebViewVC.Config Properties in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skwebview.md Defines the configuration properties for SKWebViewVC, including user-agent, JavaScript enablement, DOM storage, and callbacks for JavaScript execution and URL loading. These settings allow for fine-tuning the WebView's environment and interaction. ```kotlin class Config( val userAgent: String? = null, val javascriptEnabled: Boolean = true, val domStorageEnabled: Boolean = true, val javascriptOnStart: (() -> String?)? = null, val javascriptOnFinished: (() -> String?)? = null, val shouldOverrideUrlLoading: ((skUri: SKUri) -> Boolean)? = null, val onRequest: ((skUri: SKUri) -> Unit)? = null, val onHttpAuthRequest: ((host : String?, realm : String?, onProceed : (login : String?, password : String?) -> Unit ) -> Unit)? = null ) ``` -------------------------------- ### SKBox Component: Container for Dynamic Layouts Source: https://context7.com/useradgents/skot/llms.txt The SKBox component serves as a container for dynamic layouts and content. It can hold multiple children, switch content dynamically, be hidden or shown, and have its items updated. It also supports defining layout direction. ```kotlin import tech.skot.core.components.SKBox // Simple container with multiple children val headerBox = SKBox( logoComponent, titleComponent, actionButtonComponent ) // Dynamic content switching val contentBox = SKBox(items = null) contentBox.content = when (state) { State.LOADING -> LoadingComponent() State.ERROR -> ErrorComponent(errorMessage) State.SUCCESS -> SuccessComponent(data) } // Hide/show container contentBox.hidden = !userIsLoggedIn // Update items dynamically contentBox.items = listOf( HeaderComponent(), BodyComponent(), FooterComponent() ) // View contract with layout direction interface MyScreenVC : SKScreenVC { val verticalBox: SKBoxVC // Use asItemVertical = true for vertical layout } ``` -------------------------------- ### Include Loader Layout in XML Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skloader.md This XML snippet shows how to include a previously defined loader layout file (`my_loader.xml`) into another layout file. The included layout is given the ID `loader` to be recognized by SKLoader. ```xml ``` -------------------------------- ### Switch Current Environment Variant using Gradle Source: https://github.com/useradgents/skot/blob/develop/docs/start/addvariant.md This section describes the process of changing the active environment variant in the Skot project. It involves executing the desired switch task generated by `skSwitchTask` and then performing a Gradle sync or clean task to apply the changes. ```gradle ./gradlew yourChangeEnvTask ./gradlew clean ``` -------------------------------- ### SKWebView Component: Embed Web Content Source: https://context7.com/useradgents/skot/llms.txt The SKWebView component allows embedding web content within an application, supporting JavaScript execution, advanced configuration, navigation controls, and loading content via URL, HTML data, or POST requests. It handles various lifecycle events and permissions. ```kotlin import tech.skot.core.components.SKWebView import tech.skot.core.components.SKWebViewVC // Simple URL loading val simpleWebView = SKWebView("https://example.com") // Advanced configuration val webView = SKWebView( config = SKWebViewVC.Config( userAgent = "MyApp/1.0", javascriptEnabled = true, domStorageEnabled = true, javascriptOnFinished = { "console.log('Page loaded');" }, javascriptOnStart = { "console.log('Page starting');" }, shouldOverrideUrlLoading = { uri -> // Return true to handle URL yourself, false to let WebView handle uri.toString().contains("myapp://") }, onHttpError = { url, statusCode -> println("HTTP error $statusCode at $url") }, onRequest = { uri -> println("Loading: $uri") }, onPermissionRequested = { permissions, onResult -> // Handle camera, microphone permissions onResult(permissions) // Grant all requested } ), launch = SKWebViewVC.Launch.OpenUrl( url = "https://example.com", onFinished = { println("Page finished loading: $it") }, onError = { println("Failed to load page") } ) ) // Navigation controls webView.back(onCantBack = { println("Already at first page") }) webView.forward() webView.reload() // Execute JavaScript webView.evaluateJavascript("document.title") { result -> println("Page title: $result") } // Load HTML content webView.view.launch = SKWebViewVC.Launch.LoadData( data = "Hello World", url = null ) // POST request webView.view.launch = SKWebViewVC.Launch.OpenPostUrl( url = "https://api.example.com/submit", post = mapOf("key" to "value", "data" to "test") ) ``` -------------------------------- ### Instantiate SKAlert in Screen Implementation (Kotlin) Source: https://github.com/useradgents/skot/wiki/components/framework_components/skalert This code demonstrates how to instantiate the SKAlert class within your screen's implementation, assigning it to the alert property declared in the interface. This makes the alert functionality available for use. ```kotlin override val alert = SKAlert() ``` -------------------------------- ### Instantiate SKBottomSheet in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/skbottomsheet This snippet demonstrates how to instantiate the `SKBottomSheet` class in Kotlin. It shows the declaration of the `bottomSheet` property within a class, assigning a new instance of `SKBottomSheet` to it. This is required before you can use the bottom sheet's functionality. ```kotlin override val bottomSheet: SKBottomSheet = SKBottomSheet() ``` -------------------------------- ### Instantiate SKInput Component in Kotlin Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skinput.md This Kotlin code demonstrates how to instantiate the SKInput component for a 'lastName' field. It configures the input with a hint, specifies that it's not nullable, provides a default error message, and defines a callback function 'afterValidation' to check overall form validity. ```kotlin override val lastName: SKInput = SKInput( hint = strings.signup_form_last_name, nullable = false, defaultErrorMessage = strings.signup_form_error_message_lastname, afterValidation = { enableSignUp(formIsValid()) } ) ``` -------------------------------- ### Screen Interface Definition (Kotlin) Source: https://github.com/useradgents/skot/blob/develop/docs/architecture/modelcontract.md Defines the ModelContract interface for a screen, similar to component interfaces, allowing data transfer (subtitle) and action invocation (doClickAction). ```kotlin interface MyScreenMC { val subtitle = SKData suspend fun doClickAction() } ``` -------------------------------- ### Set Anchor and Size for SKPopupWindowVC Source: https://github.com/useradgents/skot/wiki/components/framework_components/skpopupwindow In the init block of your ScreenView, set the anchor view and size parameters for the popupWindowView. The anchor determines where the popup originates, and widthSize controls its dimensions. ```kotlin init { popupWindowView.anchor = binding.toolBarButton popupWindowView.widthSize = ViewGroup.LayoutParams.MATCH_PARENT //default ViewGroup.LayoutParams.WRAP_CONTENT popupWindowView.widthSize = ConstraintLayout.LayoutParams.WRAP_CONTENT //default ViewGroup.LayoutParams.WRAP_CONTENT } ``` -------------------------------- ### Annotate ViewContract for Component Inclusion Source: https://github.com/useradgents/skot/wiki/start/createcomponent Explains how to add the KClass of a ViewContract interface to the annotation of a `viewContract` in the view that will use it. This ensures the new component is recognized during generation. ```kotlin @SKUses([MyComponentVC::class]) interface MyScreenVC : SKScreenVC { val myComponent : MyComponentVC } ``` -------------------------------- ### Screen Interface Definition (Kotlin) Source: https://github.com/useradgents/skot/blob/develop/docs/architecture/viewcontract.md Defines the contract for a screen's interface, similar to a component but may include navigation methods. It specifies properties and subcomponents, inheriting from SKScreenVC and thus SKComponentVC. ```kotlin interface MyScreenVC: SKSCreenVC { val title : String var subTitle : String val button : SkBUttonVC val myOtherComponent : MyOtherComponentVC } ``` -------------------------------- ### Add Function to SKComponentVC Source: https://github.com/useradgents/skot/blob/develop/docs/start/createcomponent.md Adds a function `myFunction` to the `MyComponentVC` interface that accepts a callback function `onFinish`. This defines an asynchronous operation within the component. ```kotlin interface MyComponentVC : SKComponentVC { fun myFunction(onFinish : () -> Unit) } ``` -------------------------------- ### Declare SKPopupWindowVC in ScreenVC Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skpopupwindow.md Declare an instance of SKPopupWindowVC within your ScreenVC using the SKPassToParentView annotation. This sets up the popup window for later use. ```kotlin @SKPassToParentView val popupWindow : SKPopupWindowVC ``` -------------------------------- ### Instantiate SKCombo with String Choices - Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/skcombo Demonstrates how to instantiate the SKCombo component for a 'gender' field using a list of strings as choices. It configures the hint, initial choices, and a selection callback. ```kotlin override val gender = SKCombo( hint = strings.signup_form_gender, initialChoices = listOf( strings.signup_form_civility_miss, strings.signup_form_civility_madam, strings.signup_form_civility_sir ), onSelected = { enableSignUp(formIsValid()) lastName.view.requestFocus() } ) ``` -------------------------------- ### Show Basic Snackbar Message in Kotlin Source: https://github.com/useradgents/skot/wiki/components/framework_components/sksnackbar This code illustrates the basic usage of the SKSnackbar to display a simple text message. The `show` function takes the message string as its primary argument. ```kotlin snackBar.show(strings.account_screen_delete_account_success) ``` -------------------------------- ### Instantiate SKPagerWithTabs in Kotlin Class Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skpagerwithtabs.md Instantiate the SKPagerWithTabs component within your screen's implementation class. This assigns the concrete SKPagerWithTabs object to the declared pager property, making it ready for use. ```kotlin import com.your_app_package.SKPagerWithTabs override val pager = SKPagerWithTabs() ``` -------------------------------- ### SKPersistor: Store Complex Objects with Serialization Source: https://context7.com/useradgents/skot/llms.txt SKPersistor enables storing and retrieving complex data objects using serialization. It leverages kotlinx.serialization for converting objects to a storable format and back. Dependencies include SKPersistor, userPersistor, and kotlinx.serialization. ```kotlin import tech.skot.model.globalPersistor import tech.skot.model.userPersistor import kotlinx.serialization.Serializable @Serializable data class Settings(val theme: String, val notifications: Boolean) // Store complex objects with serialization suspend fun saveSettings(settings: Settings) { userPersistor.putData( serializer = Settings.serializer(), name = "app_settings", data = settings, key = null // Optional key for multiple entries ) } // Retrieve complex objects suspend fun loadSettings(): Settings? { return userPersistor.getData( serializer = Settings.serializer(), name = "app_settings", key = null ) } ``` -------------------------------- ### Associate BusinessModel with State (Kotlin) Source: https://github.com/useradgents/skot/wiki/start/addstate Associates one or more BusinessModels with a state using the @SKBms annotation. After adding the annotation, run the 'skGenerate' command to apply the changes. ```kotlin @SKBms(["UserBM"]) interface ConnectedStateDef : SKStateDef { val userId: String var token: Token } ``` -------------------------------- ### Show Alert Dialog with Input Field (Kotlin) Source: https://github.com/useradgents/skot/wiki/components/framework_components/skalert This snippet illustrates how to display an alert dialog that includes an input text field using the `withInput = true` parameter. It shows how to configure main and secondary buttons, and access the entered text via `alert.inputText`. ```kotlin alert.show( title = strings.popin_forgot_password_title, message = strings.popin_forgot_password_desc, withInput = true, secondaryButton = SKAlertVC.Button( label = strings.cta_cancel ), mainButton = SKAlertVC.Button( label = strings.cta_send ) { alert.inputText.let { if (it.isNullOrBlank()) { onResetPasswordError(true) } else { resetPaswword(it) } } }, ) ``` -------------------------------- ### XML Layout for SKFrame as Bottom Sheet Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skframe.md Configures a FrameLayout in XML to function as a bottom sheet for a SKScreen. It includes attributes for behavior, peek height, and the BottomSheetBehavior, enabling dynamic UI presentations. ```xml ``` -------------------------------- ### Set Anchor and Size for SKPopupWindow Source: https://github.com/useradgents/skot/blob/develop/docs/components/framework_components/skpopupwindow.md In the init block of your ScreenView, set the anchor view and desired width for the SKPopupWindow. The anchor determines where the popup appears relative to, and widthSize controls its horizontal dimension. ```kotlin init { popupWindowView.anchor = binding.toolBarButton popupWindowView.widthSize = ViewGroup.LayoutParams.MATCH_PARENT //default ViewGroup.LayoutParams.WRAP_CONTENT popupWindowView.widthSize = ConstraintLayout.LayoutParams.WRAP_CONTENT //default ViewGroup.LayoutParams.WRAP_CONTENT } ```