Skip to content
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

Add POC for swiftUI version of emoji-search #628

Open
wants to merge 13 commits into
base: trunk
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* Copyright (C) 2022 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 app.cash.redwood.treehouse

import app.cash.redwood.treehouse.TreehouseView.CodeListener
import app.cash.redwood.widget.SwiftUIChildren
import app.cash.redwood.widget.SwiftUIView
import app.cash.redwood.widget.Widget
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow

public class TreehouseSwiftUIView<A : AppService>(
private val treehouseApp: TreehouseApp<A>,
override val widgetSystem: TreehouseView.WidgetSystem<A>,
) : TreehouseView<A>, SwiftUIView {

public override var codeListener: CodeListener = CodeListener()
private var content: TreehouseView.Content<A>? = null

private val _children = SwiftUIChildren()
override val children: Widget.Children<*> = _children
public override var stateChangeListener: TreehouseView.OnStateChangeListener<A>? = null

override fun reset() {
_children.remove(0, _children.widgets.size)
}

override val boundContent: TreehouseView.Content<A>?
get() = content

private val mutableHostConfiguration = MutableStateFlow(HostConfiguration())

override val hostConfiguration: StateFlow<HostConfiguration>
get() = mutableHostConfiguration

public fun setContent(content: TreehouseView.Content<A>) {
treehouseApp.dispatchers.checkUi()
this.content = content
stateChangeListener?.onStateChanged(this)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (C) 2022 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 app.cash.redwood.widget

public interface SwiftUIView

public class SwiftUIChildren() : Widget.Children<SwiftUIView> {

private val _widgets = MutableListChildren<SwiftUIView>()
public val widgets: List<Widget<SwiftUIView>> = _widgets
public var observer: (() -> Unit)? = null

override fun insert(index: Int, widget: Widget<SwiftUIView>) {
_widgets.add(index, widget)
observer?.invoke()
}

override fun move(fromIndex: Int, toIndex: Int, count: Int) {
_widgets.move(fromIndex, toIndex, count)
observer?.invoke()
}

override fun remove(index: Int, count: Int) {
_widgets.remove(index, count)
observer?.invoke()
}

override fun onLayoutModifierUpdated(index: Int) {
// TODO
}
}
6 changes: 6 additions & 0 deletions samples/emoji-search/ios/README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
# iOS Emoji Search

In `app/`, run `pod install` and then `open EmojiSearchApp.xcworkspace/`.

# SwiftUI

The same app has also been built in SwiftUI.

In `swiftUI/`, run `pod install` and then `open EmojiSearchApp.xcworkspace/`.
1 change: 1 addition & 0 deletions samples/emoji-search/ios/shared/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ kotlin {
sourceSets {
commonMain {
dependencies {
api projects.redwoodLayoutSchema.widget
implementation projects.samples.emojiSearch.launcher
implementation projects.samples.emojiSearch.presenters
implementation projects.samples.emojiSearch.schema.widget.protocol
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,13 @@ package app.cash.zipline.samples.emojisearch

import app.cash.redwood.LayoutModifier
import app.cash.redwood.layout.uiview.UIViewRedwoodLayoutWidgetFactory
import app.cash.redwood.layout.widget.RedwoodLayoutWidgetFactory
import app.cash.redwood.treehouse.TreehouseSwiftUIView
import app.cash.redwood.treehouse.TreehouseUIKitView
import app.cash.redwood.treehouse.TreehouseView
import app.cash.redwood.treehouse.lazylayout.uiview.UIViewRedwoodTreehouseLazyLayoutWidgetFactory
import app.cash.redwood.widget.SwiftUIChildren
import app.cash.redwood.widget.SwiftUIView
import example.schema.widget.EmojiSearchDiffConsumingNodeFactory
import example.schema.widget.EmojiSearchWidgetFactory
import okio.ByteString
Expand All @@ -38,6 +42,10 @@ fun exposedTypes(
uiViewRedwoodTreehouseLazyLayoutWidgetFactory: UIViewRedwoodTreehouseLazyLayoutWidgetFactory<*>,
widgetSystem: TreehouseView.WidgetSystem<*>,
diffConsumingNodeFactory: EmojiSearchDiffConsumingNodeFactory<*>,
treehouseSwiftUIView: TreehouseSwiftUIView<*>,
layoutWidgetFactory: RedwoodLayoutWidgetFactory<*>,
swiftUIView: SwiftUIView,
swiftUIChildren: SwiftUIChildren,
) {
throw AssertionError()
}
Expand Down
Loading