SwiftUI vs. React Native
Source: Dev.to
Introduction
I have been working with SwiftUI and React Native for a few years, and it has been eye‑opening to see that both declarative UI frameworks share a lot in common. This becomes obvious when implementing custom views.
Example: LocationCardView
SwiftUI
struct LocationCardView: View {
@Environment(Theme.self) private var theme
var locationCoordinate: LocationCoordinate
var body: some View {
VStack(alignment: .leading, spacing: theme.spacing.md) {
Text(locationCoordinate.city)
.font(.headline)
Text(locationCoordinate.state)
.font(.caption)
Text(locationCoordinate.countryCode)
.font(.caption)
}
.locationCardViewStyle(theme)
}
}
React Native (TypeScript)
const LocationCardView = (props: LocationCardViewProps) => {
const { location } = props
const { theme } = useThemeManager((state) => state)
const styles = createLocationCardViewStyles(theme, props)
return (
{location.city}
{location.state}
{location.countryCode}
)
}
Observations
Both implementations require a similar number of lines to accomplish the same task. However, SwiftUI provides basic primitives like VStack out of the box, which can reduce memory overhead and development time. Personally, I prefer the developer experience of SwiftUI.
Discussion
What are your thoughts on both frameworks, and which do you prefer? Feel free to share your experiences in the comments.