Skip to content

Instantly share code, notes, and snippets.

View naturalwarren's full-sized avatar
🎯
Focusing

Warren Smith naturalwarren

🎯
Focusing
View GitHub Profile
@naturalwarren
naturalwarren / DataRow.swift
Last active April 18, 2023 23:31
Generated SDUIDataRow
public struct DataRow: Codable, Equatable {
public let title: String
public let subtitle: String
public let layout: Layout
public let titleHyperlink: URL?
public let accessoryView: SDUIComponent?
public enum Layout: String {
case vertical = "VERTICAL"
@naturalwarren
naturalwarren / DataRow.py
Last active April 18, 2023 23:13
Augmented SDUI DataRow
class DataRow(UIComponent):
title: str
subtitle: str
layout: Layout = Layout.HORIZONTAL
title_hyperlink: Optional[Url] = None
accessory_view = Optional[UIComponent] = None
@classmethod
def component_type(cls) -> ComponentType:
return ComponentType.DATA_ROW_STACKED
@naturalwarren
naturalwarren / ViewModel.swift
Created April 8, 2023 19:33
SDUI viewModel function
func viewModel(context: SDUIContext) -> ViewModel
@naturalwarren
naturalwarren / Action.py
Created April 8, 2023 19:32
SDUI Action
class Action(BaseModel, ABC):
sdui_action_type: ActionType
def __init__(self, **data) -> None:
data['sdui_action_type'] = self.action_type()
super().__init__(**data)
@classmethod
@abstractmethod
def action_type(cls) -> ActionType:
@naturalwarren
naturalwarren / SDUIComponent.swift
Created April 8, 2023 19:31
SDUIComponent Helper
extension SDUIComponent {
private var concreteModel: Any {
switch self {
case .button(let button):
return button
case .row(let row):
return row
case .text(let text):
return text
}
@naturalwarren
naturalwarren / DataRow+ViewModelConvertible.swift
Last active April 19, 2023 00:19
DataRow+ViewModelConvertible
extension DataRow: ViewModelConvertible {
func viewModel(context: SDUIContext) -> some ViewModel {
return DataRowViewModel(
title: self.title,
titleURL: self.titleHyperlink,
subtitle: self.subtitle,
layout: self.layout.toNativeLayout(),
accessory: accessoryView?.viewModel(context: context)
)
}
@naturalwarren
naturalwarren / SDUIComponent.ts
Created April 8, 2023 19:28
TypeScript SDUIComponent
SDUIComponent = SDUIButton | SDUIRow | SDUIText
@naturalwarren
naturalwarren / SDUIComponent.kt
Created April 8, 2023 19:27
Kotlin SDUIComponent
sealed interface SDUIComponent
data class SDUIButton: SDUIComponent
data class SDUIRow: SDUIComponent
data class SDUIText: SDUIComponent
@naturalwarren
naturalwarren / SDUIComponent.swift
Created April 8, 2023 19:26
Swift SDUIComponent
enum SDUIComponent: Equatable, Codable {
case button(SDUIButton)
case row(SDUIRow)
case text(SDUIText)
}
@naturalwarren
naturalwarren / Row.py
Last active April 8, 2023 19:20
SDUI Row With Compatibility
class Row(UIComponent):
title: str
subtitle: Optional[str] = None
@classmethod
def component_type(cls) -> ComponentType:
return ComponentType.BUTTON
@classmethod
def platform_compatibility(cls) -> Dict[Platform, Version]: