8000 Prepar v1.3.0-beta02 by mori-atsushi · Pull Request #203 · mori-atsushi/koject · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Prepar v1.3.0-beta02 #203

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 22, 2023
8000
Merged
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
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,6 @@ subprojects {
}

tasks.dokkaHtmlMultiModule {
moduleVersion.set("1.3.0-beta01")
moduleVersion.set("1.3.0-beta02")
outputDirectory.set(rootDir.resolve("docs/static/api"))
}
2 changes: 1 addition & 1 deletion docs/docs/android/activity.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following dependency is required to take advantage of the additional support

```kotlin
dependencies {
implementation("com.moriatsushi.koject:koject-android-activity:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-activity:1.3.0-beta02")
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/android/application.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ To get started, add the following dependencies for Android:

```kotlin
dependencies {
implementation("com.moriatsushi.koject:koject-android-core:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-core:1.3.0-beta02")
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/android/fragment.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ The following dependency is required to take advantage of the additional support

```kotlin
dependencies {
implementation("com.moriatsushi.koject:koject-android-fragment:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-fragment:1.3.0-beta02")
}
```

Expand Down
12 changes: 6 additions & 6 deletions docs/docs/android/viewmodel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ Add the appropriate dependencies for the injection target:
```kotlin
dependencies {
// Inject ViewModel into Activity
implementation("com.moriatsushi.koject:koject-android-activity:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-activity:1.3.0-beta02")
// Inject ViewModel into Fragment
implementation("com.moriatsushi.koject:koject-android-fragment:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-fragment:1.3.0-beta02")
// ViewModelFactory only
implementation("com.moriatsushi.koject:koject-android-viewmodel:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-android-viewmodel:1.3.0-beta02")
}
```

Expand Down Expand Up @@ -75,15 +75,15 @@ Refer to the [documentation](/docs/compose/viewmodel) to inject ViewModels in Je

:::

:::note MIGRATION (VERSION 1.3.0-beta01)
:::note MIGRATION (VERSION 1.3.0-beta02)

As of version v1.3.0-beta01, `injectViewModels()` has been renamed to `lazyViewModels()`:
As of version v1.3.0-beta02, `injectViewModels()` has been renamed to `lazyViewModels()`:

```kotlin
// Until v1.1.0
private val viewModel: TopViewModel by injectViewModels()

// Since v1.3.0-beta01
// Since v1.3.0-beta02
private val viewModel: TopViewModel by lazyViewModels()
```
:::
Expand Down
2 changes: 1 addition & 1 deletion docs/docs/compose/core.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ To use Koject for injection into Composable functions, you need to add the follo

```kotlin
dependencies {
implementation("com.moriatsushi.koject:koject-compose-core:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-compose-core:1.3.0-beta02")
}
```

Expand Down
2 changes: 1 addition & 1 deletion docs/docs/compose/viewmodel.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To inject ViewModels into Composable, add the following dependencies:

```kotlin
dependencies {
implementation("com.moriatsushi.koject:koject-compose-viewmodel:1.3.0-beta01")
implementation("com.moriatsushi.koject:koject-compose-viewmodel:1.3.0-beta02")
}
```

Expand Down
77 changes: 77 additions & 0 deletions docs/docs/ios/basic.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
import {
Provides,
} from '@site/src/components/CodeLink';

# Inject into Swift
Koject supports KMM projects, allowing you to share code between Android and iOS.
This document explains how to use the dependencies provided by Kotlin in your Swift code.

## Getting Started

To call Koject from Swift, you need to define the necessary actions in Kotlin.

First, create a `KojectHelper` object in the `iosMain` folder and add a `start` function for initialization.

```kotlin title="src/iosMain/kotlin/KojectHelper.ios.kt"
object KojectHelper {
fun start() {
Koject.start()
}
}
```

Next, call `KojectHelper.shared.start()` in `@main` in Swift to start Koject.

```swift title="MyApp.swift"
import SwiftUI
import shared

@main
struct MyApp: App {
init() {
KojectHelper.shared.start()
}

var body: some Scene {
/* ... */
}
}
```

Define the necessary dependencies in Kotlin and provide them using <Provides/>.

```kotlin title="src/commonMain/kotlin/SampleRepository.kt"
@Provides
@Singleton
class SampleRepository
```
```kotlin title="src/commonMain/kotlin/SampleViewModel.kt"
@Provides
class SampleViewModel(
private val repository: SampleRepository
)
```

Add the necessary dependencies on the Swift side to `KojectHelper` as shown below.

```kotlin title="src/iosMain/kotlin/KojectHelper.ios.kt"
object KojectHelper {
fun start() {
Koject.start()
}

fun injectSampleViewModel(): SampleViewModel {
return inject()
}
}
```

You can use it by calling `KojectHelper.shared.injectSampleViewModel()` in Swift.

```swift title="SampleState.swift"
import shared

class SampleState {
private let viewModel = KojectHelper.shared.injectSampleViewModel()
}
```
6 changes: 6 additions & 0 deletions docs/docs/ios/index.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# iOS (KMM)
Koject supports [Kotlin Multiplatform Mobile](https://kotlinlang.org/lp/mobile/)(KMM) and can also be used on iOS.

import DocCardList from '@theme/DocCardList';

<DocCardList />
145 changes: 145 additions & 0 deletions docs/docs/ios/tests.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
import {
KojectRunTest,
KojectStartTest,
} from '@site/src/components/CodeLink';

# iOS tests
There are two ways to test KMM iOS code: testing with Kotlin only and integration testing from iOS.
Here is an introduction to both methods.

:::info LINK

To understand the basics of testing, please refer to the [Test documentation](/docs/test) first.

:::

## Testing with Kotlin only

To test with Kotlin only, you can use <KojectRunTest/> or <KojectStartTest/> to use the DI container for testing.

```kotlin
@Provides
class Controller
```
```kotlin
class SampleTest() {
@Test
fun test() = Koject.runTest {
val controller = inject<Controller>() // can be injected
}
}
```

Please refer to the [Test documentation](/docs/test) for more details.

## iOS Unit tests
To test including code written in Swift, use [XCTest](https://developer.apple.com/documentation/xctest).

First, add the `koject-test` dependency to `iosMain` in shared/build.gradle.kts.

```diff title="shared/build.gradle.kts"
kotlin {
/* ... */

sourceSets {
val commonMain by getting {
dependencies {
implementation("com.moriatsushi.koject:koject-core:1.3.0-beta02")
}
}

val iosMain by getting {
+ dependencies {
+ implementation("com.moriatsushi.koject:koject-test:1.3.0-beta02")
+ }
}
}
}
```

Create a `KojectHelper` object and add `startTest()` and `stop()` functions.

```kotlin title="src/iosMain/kotlin/KojectHelper.ios.kt"
object KojectHelper {
fun start() {
Koject.start()
}

fun startTest() {
Koject.startTest()
}

fun stop() {
Koject.stop()
}
}
```

You can test with the DI container for testing by calling `startTest` in `setUpWithError` and `stop` in `tearDownWithError`.

```swift title="SampleStateTests.swift"
import XCTest
@testable import ios
@testable import shared

final class SampleStateTests: XCTestCase {
override func setUpWithError() throws {
KojectHelper.shared.startTest()
}

override func tearDownWithError() throws {
KojectHelper.shared.stop()
}

func test() throws {
/* ... */
}
}
```

## iOS UI tests
When performing UI tests, the DI container for the application is used, so branching must be done on the application side.

First, create a branch in `@main` as follows:

```swift title="MyApp.swift"
import SwiftUI
import shared

@main
struct MyApp: App {
init() {
#if DEBUG
let isTesting = CommandLine.arguments.contains("TESTING")
if isTesting {
KojectHelper.shared.startTest()
} else {
KojectHelper.shared.start()
}
#else
KojectHelper.shared.start()
#endif
}

var body: some Scene {
/* ... */
}
}
```

Specify `launchArguments` when starting the test, and UI tests can be executed using the DI container for testing.

```swift title="UITests.swift"
import XCTest

final class UITests: XCTestCase {
let app = XCUIApplication()

func testAddTask() {
app.launchArguments = ["TESTING"]
app.launch()

/* ... */
}
}
```
Loading
0