Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/eneskaraosman/jsondrivenui
JSON into native SwiftUI View to build UI for Apple ecosystem
https://github.com/eneskaraosman/jsondrivenui
backend-driven-ui ios json-driven-ui server-driven-ui swiftui
Last synced: about 1 month ago
JSON representation
JSON into native SwiftUI View to build UI for Apple ecosystem
- Host: GitHub
- URL: https://github.com/eneskaraosman/jsondrivenui
- Owner: EnesKaraosman
- License: mit
- Created: 2020-11-27T11:34:43.000Z (about 4 years ago)
- Default Branch: main
- Last Pushed: 2024-04-10T11:46:19.000Z (9 months ago)
- Last Synced: 2024-10-30T17:26:28.669Z (about 2 months ago)
- Topics: backend-driven-ui, ios, json-driven-ui, server-driven-ui, swiftui
- Language: Swift
- Homepage:
- Size: 262 KB
- Stars: 90
- Watchers: 3
- Forks: 12
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# JSONDrivenUI
Convert your json into native `View`s
Simply construct `JSONDataView(json: Data)` view to setup UI.
OK JSON but how?
* Specify your view's `type` ([ViewType](../main/Sources/JSONDrivenUI/ViewType.swift))
* `properties` of it ([ViewProperties](../main/Sources/JSONDrivenUI/ViewProperties.swift) )
* `values` (like text, imageUrl, systemIconName, localImageName) ([Values](../main/Sources/JSONDrivenUI/Values.swift) )
* `subviews` (for stacks, list & scrollView)### Supported View Types
Image
- For images we have 3 options. (Order is also like below in case more than 1 set)
* systemIconName
* localImageName
* imageUrl
```json
{
"type": "Image",
"values": {
"systemIconName": "person.crop.circle"
},
"properties": {
"width": 60,
"height": 60
}
}
````resizable()` & `scaledToFit()` modifiers applied by default.
Text
* font (largeTitle, title, headline, subheadline, body, callout, footnote, caption)
* fontWeight (ultraLight, thin, light, regular, medium, semibold, bold, heavy, black)```json
{
"type": "Text",
"values": {
"text": "Enes Karaosman"
},
"properties": {
"fontWeight": "semibold",
"font": "body"
}
}
```VStack
* spacing: Int
* horizontalAlignment: (leading, center, trailing) // default is center```json
{
"type": "VStack",
"properties": {
"spacing": 8,
"horizontalAlignment": "leading",
..
},
"subviews": [
...
]
}
```HStack
* spacing: Int
* verticalAlignment: (top, bottom, center, firstTextBaseline, lastTextBaseline) // default is center```json
{
"type": "HStack",
"properties": {
"spacing": 8,
"verticalAlignment": "top",
..
},
"subviews": [
...
]
}
```ZStack
```json
{
"type": "ZStack",
"subviews": [
{
"type": "Circle",
"properties": {
"foregroundColor": "#ff0000",
"width": 200
}
},
{
"type": "Circle",
"properties": {
"foregroundColor": "#00ff00",
"width": 150
}
},
{
"type": "Circle",
"properties": {
"foregroundColor": "#0000ff",
"width": 100
}
}
]
}
```List
```json
{
"type": "List",
"subviews": [
{ ... },
{ ... },
{ ... }
]
}
```ScrollView
Scroll view content (subviews) automatically placed in Stack according to given axis.
If axis is vertical placed in VStack, otherwise in HStack.```json
{
"type": "ScrollView",
"properties": {
"axis": "vertical",
"showsIndicators": true
}
"subviews": [
{ ... },
{ ... },
{ ... }
]
}
```* Spacer (`minLenght: Int?`)
* Rectangle
* Circle
* Divider#### Examples
```json
{
"type": "HStack",
"properties": {
"height": 100,
"padding": 16,
"spacing": 16
},
"subviews": [
{
"type": "Image",
"values": {
"systemIconName": "person.crop.circle"
},
"properties": {
"width": 60,
"height": 60
}
},
{
"type": "VStack",
"properties": {
"foregroundColor": "#f0f00f",
"spacing": 8,
"horizontalAlignment": "leading"
},
"subviews": [
{
"type": "Text",
"values": {
"text": "Enes Karaosman"
},
"properties": {
"fontWeight": "semibold",
"foregroundColor": "#000000"
}
},
{
"type": "Text",
"values": {
"text": "Here is a bit description like text"
},
"properties": {
"foregroundColor": "#070707"
}
}
]
}
]
}
```
```json
{
"type": "VStack",
"subviews": [
{
"type": "Text",
"properties": {
"font": "title"
},
"values": {
"text": "LARGE TITLE TEXT"
}
},
{
"type": "Image",
"values": {
"imageUrl": "http://picsum.photos/400/200"
},
"properties": {
"padding": 16,
"height": 200
}
},
{
"type": "Text",
"properties": {
"padding": 16,
"font": "title",
"fontWeight": "semibold"
},
"values": {
"text": "Semibold Title"
}
},
{
"type": "List",
"properties": {
"horizontalAlignment": "leading",
"spacing": 16,
"padding": 8
},
"subviews": [
{
"type": "HStack",
"properties": {
"foregroundColor": "#001238",
"spacing": 8
},
"subviews": [
{
"type": "Image",
"properties": {
"height": 70
},
"values": {
"imageUrl": "http://picsum.photos/70/70"
}
},
{
"type": "VStack",
"properties": {
"spacing": 4,
"horizontalAlignment": "leading"
},
"subviews": [
{
"type": "Text",
"values": { "text" : "Item.1 Title" }
},
{
"type": "Text",
"properties": {
"foregroundColor": "#828282"
},
"values": { "text" : "Here is multiline description text in VStack which is inside HStack" }
}
]
}
]
},
{
"type": "HStack",
"properties": {
"foregroundColor": "#001238",
"spacing": 8
},
"subviews": [
{
"type": "Image",
"properties": {
"height": 70
},
"values": {
"imageUrl": "http://picsum.photos/70/70"
}
},
{
"type": "VStack",
"properties": {
"spacing": 4,
"horizontalAlignment": "leading"
},
"subviews": [
{
"type": "Text",
"values": { "text" : "Item.2 Title" }
},
{
"type": "Text",
"properties": {
"foregroundColor": "#828282"
},
"values": { "text" : "Here is second multiline description text in VStack which is inside HStack" }
}
]
}
]
}
]
}
]
}
```