Browse Source
* COMPOSE-351, iOS Simplify Swift code in examples - change indent from tabs to spaces - simplify and inline SwiftUI ContentView structure https://youtrack.jetbrains.com/issue/COMPOSE-351/remove-redundant-struct-ContentView Co-authored-by: Ivan Matkov <ivan.matkov@jetbrains.com>pull/3618/head
dima.avdeev
1 year ago
committed by
GitHub
32 changed files with 223 additions and 284 deletions
@ -0,0 +1,30 @@ |
|||||||
|
import SwiftUI |
||||||
|
|
||||||
|
let gradient = LinearGradient( |
||||||
|
colors: [ |
||||||
|
Color(red: 0.933, green: 0.937, blue: 0.953), |
||||||
|
Color(red: 0.902, green: 0.941, blue: 0.949) |
||||||
|
], |
||||||
|
startPoint: .topLeading, endPoint: .bottomTrailing |
||||||
|
) |
||||||
|
|
||||||
|
@main |
||||||
|
struct iOSApp: App { |
||||||
|
var body: some Scene { |
||||||
|
WindowGroup { |
||||||
|
TabView { |
||||||
|
ComposeInsideSwiftUIScreen() |
||||||
|
.tabItem { |
||||||
|
Label("Group Chat", systemImage: "rectangle.3.group.bubble.left") |
||||||
|
} |
||||||
|
|
||||||
|
YetAnotherSwiftUIScreen() |
||||||
|
.tabItem { |
||||||
|
Label("Settings", systemImage: "gear") |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
.accentColor(Color(red: 0.671, green: 0.365, blue: 0.792)).preferredColorScheme(.light) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,26 +0,0 @@ |
|||||||
import SwiftUI |
|
||||||
|
|
||||||
let gradient = LinearGradient( |
|
||||||
colors: [ |
|
||||||
Color(red: 0.933, green: 0.937, blue: 0.953), |
|
||||||
Color(red: 0.902, green: 0.941, blue: 0.949) |
|
||||||
], |
|
||||||
startPoint: .topLeading, endPoint: .bottomTrailing |
|
||||||
) |
|
||||||
|
|
||||||
@main |
|
||||||
struct iOSApp: App { |
|
||||||
var body: some Scene { |
|
||||||
WindowGroup { |
|
||||||
TabView { |
|
||||||
ComposeInsideSwiftUIScreen() |
|
||||||
.tabItem { Label("Group Chat", systemImage: "rectangle.3.group.bubble.left") } |
|
||||||
|
|
||||||
YetAnotherSwiftUIScreen() |
|
||||||
.tabItem { Label("Settings", systemImage: "gear") } |
|
||||||
|
|
||||||
} |
|
||||||
.accentColor(Color(red: 0.671, green: 0.365, blue: 0.792)).preferredColorScheme(.light) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable { |
|
||||||
func makeUIViewController(context: Context) -> UIViewController { |
|
||||||
Main_iosKt.MainViewController() |
|
||||||
} |
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
|
||||||
} |
|
||||||
|
|
||||||
struct ContentView: View { |
|
||||||
var body: some View { |
|
||||||
ComposeView() |
|
||||||
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,13 +1,24 @@ |
|||||||
|
import UIKit |
||||||
import SwiftUI |
import SwiftUI |
||||||
|
import shared |
||||||
|
|
||||||
@main |
@main |
||||||
struct iOSApp: App { |
struct iOSApp: App { |
||||||
var body: some Scene { |
var body: some Scene { |
||||||
WindowGroup { |
WindowGroup { |
||||||
ZStack { |
ZStack { |
||||||
Color.white.ignoresSafeArea(.all) // status bar color |
Color.white.ignoresSafeArea(.all) // status bar color |
||||||
ContentView() |
ComposeView() |
||||||
}.preferredColorScheme(.light) |
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler |
||||||
} |
}.preferredColorScheme(.light) |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
struct ComposeView: UIViewControllerRepresentable { |
||||||
|
func makeUIViewController(context: Context) -> UIViewController { |
||||||
|
Main_iosKt.MainViewController() |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
||||||
|
} |
||||||
|
@ -1,21 +0,0 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable { |
|
||||||
func makeUIViewController(context: Context) -> UIViewController { |
|
||||||
Main_iosKt.MainViewController() |
|
||||||
} |
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
|
||||||
} |
|
||||||
|
|
||||||
struct ContentView: View { |
|
||||||
var body: some View { |
|
||||||
ComposeView() |
|
||||||
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,13 +1,24 @@ |
|||||||
|
import UIKit |
||||||
import SwiftUI |
import SwiftUI |
||||||
|
import shared |
||||||
|
|
||||||
@main |
@main |
||||||
struct iOSApp: App { |
struct iOSApp: App { |
||||||
var body: some Scene { |
var body: some Scene { |
||||||
WindowGroup { |
WindowGroup { |
||||||
ZStack { |
ZStack { |
||||||
Color(#colorLiteral(red: 0.235, green: 0.247, blue: 0.255, alpha: 1)).ignoresSafeArea(.all) |
Color(#colorLiteral(red: 0.235, green: 0.247, blue: 0.255, alpha: 1)).ignoresSafeArea(.all) |
||||||
ContentView() |
ComposeView() |
||||||
}.preferredColorScheme(.dark) |
.ignoresSafeArea(.all, edges: .bottom) // Compose has own keyboard handler |
||||||
} |
}.preferredColorScheme(.dark) |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
struct ComposeView: UIViewControllerRepresentable { |
||||||
|
func makeUIViewController(context: Context) -> UIViewController { |
||||||
|
Main_iosKt.MainViewController() |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
||||||
|
} |
||||||
|
@ -1,37 +0,0 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
|
|
||||||
let gradient = LinearGradient( |
|
||||||
colors: [ |
|
||||||
Color.black.opacity(0.6), |
|
||||||
Color.black.opacity(0.6), |
|
||||||
Color.black.opacity(0.5), |
|
||||||
Color.black.opacity(0.3), |
|
||||||
Color.black.opacity(0.0), |
|
||||||
], |
|
||||||
startPoint: .top, endPoint: .bottom |
|
||||||
) |
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable { |
|
||||||
func makeUIViewController(context: Context) -> UIViewController { |
|
||||||
let controller = Main_iosKt.MainViewController() |
|
||||||
controller.overrideUserInterfaceStyle = .light |
|
||||||
return controller |
|
||||||
} |
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
|
||||||
} |
|
||||||
|
|
||||||
struct ContentView: View { |
|
||||||
var body: some View { |
|
||||||
ZStack { |
|
||||||
ComposeView() |
|
||||||
.ignoresSafeArea(.all) // Compose has own keyboard handler |
|
||||||
VStack { |
|
||||||
gradient.ignoresSafeArea(edges: .top).frame(height: 0) |
|
||||||
Spacer() |
|
||||||
} |
|
||||||
}.preferredColorScheme(.dark) |
|
||||||
} |
|
||||||
} |
|
@ -1,10 +1,41 @@ |
|||||||
|
import UIKit |
||||||
import SwiftUI |
import SwiftUI |
||||||
|
import shared |
||||||
|
|
||||||
|
let gradient = LinearGradient( |
||||||
|
colors: [ |
||||||
|
Color.black.opacity(0.6), |
||||||
|
Color.black.opacity(0.6), |
||||||
|
Color.black.opacity(0.5), |
||||||
|
Color.black.opacity(0.3), |
||||||
|
Color.black.opacity(0.0), |
||||||
|
], |
||||||
|
startPoint: .top, endPoint: .bottom |
||||||
|
) |
||||||
|
|
||||||
@main |
@main |
||||||
struct iOSApp: App { |
struct iOSApp: App { |
||||||
var body: some Scene { |
var body: some Scene { |
||||||
WindowGroup { |
WindowGroup { |
||||||
ContentView() |
ZStack { |
||||||
} |
ComposeView() |
||||||
} |
.ignoresSafeArea(.all) // Compose has own keyboard handler |
||||||
} |
VStack { |
||||||
|
gradient.ignoresSafeArea(edges: .top).frame(height: 0) |
||||||
|
Spacer() |
||||||
|
} |
||||||
|
}.preferredColorScheme(.dark) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
struct ComposeView: UIViewControllerRepresentable { |
||||||
|
func makeUIViewController(context: Context) -> UIViewController { |
||||||
|
let controller = Main_iosKt.MainViewController() |
||||||
|
controller.overrideUserInterfaceStyle = .light |
||||||
|
return controller |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { |
||||||
|
} |
||||||
|
} |
||||||
|
@ -0,0 +1,20 @@ |
|||||||
|
import SwiftUI |
||||||
|
|
||||||
|
@main |
||||||
|
struct iOSApp: App { |
||||||
|
var body: some Scene { |
||||||
|
WindowGroup { |
||||||
|
TabView { |
||||||
|
ComposeInSwiftUIScreen() |
||||||
|
.tabItem { |
||||||
|
Label("Compose in SwiftUI", systemImage: "star.fill") |
||||||
|
} |
||||||
|
|
||||||
|
YetAnotherSwiftUIScreen() |
||||||
|
.tabItem { |
||||||
|
Label("SwiftUI", systemImage: "gear") |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
@ -1,17 +0,0 @@ |
|||||||
import SwiftUI |
|
||||||
|
|
||||||
@main |
|
||||||
struct iOSApp: App { |
|
||||||
var body: some Scene { |
|
||||||
WindowGroup { |
|
||||||
TabView { |
|
||||||
ComposeInSwiftUIScreen() |
|
||||||
.tabItem { Label("Compose in SwiftUI", systemImage: "star.fill") } |
|
||||||
|
|
||||||
YetAnotherSwiftUIScreen() |
|
||||||
.tabItem { Label("SwiftUI", systemImage: "gear") } |
|
||||||
|
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,7 +1,7 @@ |
|||||||
# SwiftUI in Compose |
# SwiftUI in Compose |
||||||
|
|
||||||
This example shows how to use a SwiftUI view in a Compose application. |
This example shows how to use a SwiftUI view in a Compose application. |
||||||
Pay attention to file [main.ios.kt](shared%2Fsrc%2FiosMain%2Fkotlin%2Fmain.ios.kt) and [ComposeViewControllerToSwiftUI.swift](iosApp%2FiosApp%2FComposeViewControllerToSwiftUI.swift) |
Pay attention to file [main.ios.kt](shared%2Fsrc%2FiosMain%2Fkotlin%2Fmain.ios.kt) and [ComposeViewControllerRepresentable.swift](iosApp%2FiosApp%2FComposeViewControllerRepresentable.swift) |
||||||
|
|
||||||
![screenshot.png](screenshot.png) |
![screenshot.png](screenshot.png) |
||||||
|
|
||||||
|
@ -1,7 +1,16 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
import SwiftUI |
||||||
import shared |
import shared |
||||||
import MapKit |
import UIKit |
||||||
|
|
||||||
|
@main |
||||||
|
struct iOSApp: App { |
||||||
|
var body: some Scene { |
||||||
|
WindowGroup { |
||||||
|
ComposeViewControllerToSwiftUI() |
||||||
|
.ignoresSafeArea(.all) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
struct ComposeViewControllerToSwiftUI: UIViewControllerRepresentable { |
struct ComposeViewControllerToSwiftUI: UIViewControllerRepresentable { |
||||||
func makeUIViewController(context: Context) -> UIViewController { |
func makeUIViewController(context: Context) -> UIViewController { |
@ -1,13 +0,0 @@ |
|||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
import UIKit |
|
||||||
|
|
||||||
@main |
|
||||||
struct iOSApp: App { |
|
||||||
var body: some Scene { |
|
||||||
WindowGroup { |
|
||||||
ComposeViewControllerToSwiftUI() |
|
||||||
.ignoresSafeArea(.all) |
|
||||||
} |
|
||||||
} |
|
||||||
} |
|
@ -1,21 +0,0 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable { |
|
||||||
func makeUIViewController(context: Context) -> UIViewController { |
|
||||||
Main_iosKt.MainViewController() |
|
||||||
} |
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
|
||||||
} |
|
||||||
|
|
||||||
struct ContentView: View { |
|
||||||
var body: some View { |
|
||||||
ComposeView() |
|
||||||
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,22 @@ |
|||||||
|
import UIKit |
||||||
import SwiftUI |
import SwiftUI |
||||||
|
import shared |
||||||
|
|
||||||
@main |
@main |
||||||
struct iOSApp: App { |
struct iOSApp: App { |
||||||
var body: some Scene { |
var body: some Scene { |
||||||
WindowGroup { |
WindowGroup { |
||||||
ContentView() |
ComposeView() |
||||||
} |
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
struct ComposeView: UIViewControllerRepresentable { |
||||||
|
func makeUIViewController(context: Context) -> UIViewController { |
||||||
|
Main_iosKt.MainViewController() |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { |
||||||
|
} |
||||||
|
} |
||||||
|
@ -1,21 +0,0 @@ |
|||||||
import UIKit |
|
||||||
import SwiftUI |
|
||||||
import shared |
|
||||||
|
|
||||||
struct ComposeView: UIViewControllerRepresentable { |
|
||||||
func makeUIViewController(context: Context) -> UIViewController { |
|
||||||
Main_iosKt.MainViewController() |
|
||||||
} |
|
||||||
|
|
||||||
func updateUIViewController(_ uiViewController: UIViewController, context: Context) {} |
|
||||||
} |
|
||||||
|
|
||||||
struct ContentView: View { |
|
||||||
var body: some View { |
|
||||||
ComposeView() |
|
||||||
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1,10 +1,22 @@ |
|||||||
|
import UIKit |
||||||
import SwiftUI |
import SwiftUI |
||||||
|
import shared |
||||||
|
|
||||||
@main |
@main |
||||||
struct iOSApp: App { |
struct iOSApp: App { |
||||||
var body: some Scene { |
var body: some Scene { |
||||||
WindowGroup { |
WindowGroup { |
||||||
ContentView() |
ComposeView() |
||||||
} |
.ignoresSafeArea(.keyboard) // Compose has own keyboard handler |
||||||
} |
} |
||||||
} |
} |
||||||
|
} |
||||||
|
|
||||||
|
struct ComposeView: UIViewControllerRepresentable { |
||||||
|
func makeUIViewController(context: Context) -> UIViewController { |
||||||
|
Main_iosKt.MainViewController() |
||||||
|
} |
||||||
|
|
||||||
|
func updateUIViewController(_ uiViewController: UIViewController, context: Context) { |
||||||
|
} |
||||||
|
} |
||||||
|
Loading…
Reference in new issue