-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add iOS frontend for test app (#1473)
- Loading branch information
1 parent
d930d78
commit 107f6eb
Showing
22 changed files
with
1,133 additions
and
4 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
apply plugin: 'org.jetbrains.kotlin.multiplatform' | ||
|
||
kotlin { | ||
[ | ||
iosArm64(), | ||
iosX64(), | ||
iosSimulatorArm64(), | ||
].each { iosTarget -> | ||
iosTarget.binaries.framework { | ||
baseName = 'TestAppKt' | ||
} | ||
} | ||
|
||
sourceSets { | ||
commonMain { | ||
dependencies { | ||
implementation projects.testApp.launcher | ||
implementation projects.testApp.presenterTreehouse | ||
implementation projects.testApp.schema.widgetProtocol | ||
implementation projects.redwoodLayoutUiview | ||
implementation projects.redwoodLazylayoutUiview | ||
} | ||
} | ||
} | ||
} |
75 changes: 75 additions & 0 deletions
75
test-app/ios-shared/src/commonMain/kotlin/com/example/redwood/testing/ios/TestAppLauncher.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.example.redwood.testing.ios | ||
|
||
import app.cash.redwood.treehouse.EventListener | ||
import app.cash.redwood.treehouse.TreehouseApp | ||
import app.cash.redwood.treehouse.TreehouseAppFactory | ||
import app.cash.zipline.Zipline | ||
import app.cash.zipline.ZiplineManifest | ||
import app.cash.zipline.loader.ManifestVerifier.Companion.NO_SIGNATURE_CHECKS | ||
import app.cash.zipline.loader.asZiplineHttpClient | ||
import app.cash.zipline.loader.withDevelopmentServerPush | ||
import com.example.redwood.testing.launcher.TestAppSpec | ||
import com.example.redwood.testing.treehouse.HostApi | ||
import com.example.redwood.testing.treehouse.TestAppPresenter | ||
import kotlinx.coroutines.CoroutineScope | ||
import kotlinx.coroutines.MainScope | ||
import kotlinx.coroutines.flow.flowOf | ||
import platform.Foundation.NSLog | ||
import platform.Foundation.NSURLSession | ||
|
||
class TestAppLauncher( | ||
private val nsurlSession: NSURLSession, | ||
private val hostApi: HostApi, | ||
) { | ||
private val coroutineScope: CoroutineScope = MainScope() | ||
private val manifestUrl = "http://localhost:8080/manifest.zipline.json" | ||
|
||
@Suppress("unused") // Invoked in Swift. | ||
fun createTreehouseApp(): TreehouseApp<TestAppPresenter> { | ||
val ziplineHttpClient = nsurlSession.asZiplineHttpClient() | ||
|
||
val treehouseAppFactory = TreehouseAppFactory( | ||
httpClient = ziplineHttpClient, | ||
manifestVerifier = NO_SIGNATURE_CHECKS, | ||
eventListener = object : EventListener() { | ||
override fun codeLoadFailed(app: TreehouseApp<*>, manifestUrl: String?, exception: Exception, startValue: Any?) { | ||
NSLog("Treehouse: codeLoadFailed: $exception") | ||
} | ||
|
||
override fun codeLoadSuccess(app: TreehouseApp<*>, manifestUrl: String?, manifest: ZiplineManifest, zipline: Zipline, startValue: Any?) { | ||
NSLog("Treehouse: codeLoadSuccess") | ||
} | ||
}, | ||
) | ||
|
||
val manifestUrlFlow = flowOf(manifestUrl) | ||
.withDevelopmentServerPush(ziplineHttpClient) | ||
|
||
val treehouseApp = treehouseAppFactory.create( | ||
appScope = coroutineScope, | ||
spec = TestAppSpec( | ||
manifestUrl = manifestUrlFlow, | ||
hostApi = hostApi, | ||
), | ||
) | ||
|
||
treehouseApp.start() | ||
|
||
return treehouseApp | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
test-app/ios-shared/src/commonMain/kotlin/com/example/redwood/testing/ios/exposed.kt
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
/* | ||
* Copyright (C) 2023 Square, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
@file:Suppress("unused", "UNUSED_PARAMETER") | ||
|
||
package com.example.redwood.testing.ios | ||
|
||
import app.cash.redwood.Modifier | ||
import app.cash.redwood.layout.uiview.UIViewRedwoodLayoutWidgetFactory | ||
import app.cash.redwood.lazylayout.uiview.UIViewRedwoodLazyLayoutWidgetFactory | ||
import app.cash.redwood.treehouse.AppService | ||
import app.cash.redwood.treehouse.Content | ||
import app.cash.redwood.treehouse.TreehouseUIView | ||
import app.cash.redwood.treehouse.TreehouseView | ||
import app.cash.redwood.treehouse.TreehouseView.WidgetSystem | ||
import app.cash.redwood.treehouse.bindWhenReady | ||
import com.example.redwood.testing.treehouse.TestAppPresenter | ||
import com.example.redwood.testing.widget.TestSchemaProtocolNodeFactory | ||
import com.example.redwood.testing.widget.TestSchemaWidgetFactories | ||
import com.example.redwood.testing.widget.TestSchemaWidgetFactory | ||
import okio.ByteString | ||
import okio.ByteString.Companion.toByteString | ||
import okio.Closeable | ||
import platform.Foundation.NSData | ||
|
||
// Used to export types to Objective-C / Swift. | ||
fun exposedTypes( | ||
testAppPresenter: TestAppPresenter, | ||
testAppLauncher: TestAppLauncher, | ||
testSchemaWidgetFactory: TestSchemaWidgetFactory<*>, | ||
protocolNodeFactory: TestSchemaProtocolNodeFactory<*>, | ||
treehouseUIView: TreehouseUIView, | ||
uiViewRedwoodLayoutWidgetFactory: UIViewRedwoodLayoutWidgetFactory, | ||
uiViewRedwoodLazyLayoutWidgetFactory: UIViewRedwoodLazyLayoutWidgetFactory, | ||
widgetSystem: WidgetSystem<*>, | ||
widgetFactories: TestSchemaWidgetFactories<*>, | ||
) { | ||
throw AssertionError() | ||
} | ||
|
||
fun byteStringOf(data: NSData): ByteString = data.toByteString() | ||
|
||
fun modifier(): Modifier = Modifier | ||
|
||
fun <A : AppService> bindWhenReady( | ||
content: Content, | ||
view: TreehouseView<*>, | ||
): Closeable = content.bindWhenReady(view) |
Oops, something went wrong.