Last active
February 12, 2020 23:02
-
-
Save badrinathvm/c9e55d063edb3caabb9dc786a87e141f to your computer and use it in GitHub Desktop.
SwiftUI_UIKit
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
#if canImport(SwiftUI) && !arch(arm) && os(iOS) || os(watchOS) // fails compilation | |
#if canImport(SwiftUI) && !arch(arm) && os(iOS) && os(watchOS) // passes compilation | |
@available(iOS 13.0, *) | |
struct AdviceContentView: View { | |
var slideTitle: String | |
var slideDescription: String | |
var iconProps:ImageComponent | |
var body: some View { | |
VStack { | |
iconProps[keyPath: \ImageComponent.image.value].map( { | |
Image(uiImage: $0) | |
.resizable() | |
.modifier(ImageModifier(imageHeight: iconProps[keyPath: \ImageComponent.imageHeight])) | |
}) ?? Image("lightBulb") //fallback case ( happens only if network calls fails ) | |
.resizable() | |
.modifier(ImageModifier(imageHeight: iconProps[keyPath: \ImageComponent.imageHeight])) | |
Text(slideTitle) | |
.font(.system(size: 17, weight: Font.Weight.bold)) | |
.padding(.horizontal, 16) | |
.modifier(CommonModifier()) | |
Text(slideDescription) | |
.padding() | |
.font(.system(size: 15)) | |
.modifier(CommonModifier()) | |
Spacer() | |
} | |
} | |
} | |
@available(iOS 13.0, *) | |
struct CommonModifier: ViewModifier { | |
func body(content: _ViewModifier_Content<CommonModifier>) -> some View { | |
content.foregroundColor(Color.black) | |
.multilineTextAlignment(TextAlignment.center) | |
} | |
} | |
@available(iOS 13.0, *) | |
struct ImageModifier: ViewModifier { | |
var imageHeight:CGFloat | |
func body(content: Content) -> some View { | |
content | |
.aspectRatio(contentMode: ContentMode.fit) | |
.frame(height:imageHeight) | |
.padding(EdgeInsets(top: 24, leading: 0, bottom: 14, trailing: 0)) | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
If i make it as
#if canImport(SwiftUI) && !arch(arm) && os(iOS) && os(watchOS)
it compiles fine .. but this code is only for iOS .. so i made#if canImport(SwiftUI) && !arch(arm) && os(iOS) || os(watchOS)
compilation fails :(