Skip to content

Instantly share code, notes, and snippets.

@ClassicOldSong
Last active December 19, 2022 18:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ClassicOldSong/6db5fb2ff331130a26504fec05ceabc6 to your computer and use it in GitHub Desktop.
Save ClassicOldSong/6db5fb2ff331130a26504fec05ceabc6 to your computer and use it in GitHub Desktop.
Solidjs + NativeScript + SwiftUI
import { Application } from "@nativescript/core"
import { render } from "@dominative/solid"
import { createSignal } from "solid-js"
import { registerElement } from 'dominative'
import { SwiftUI, registerSwiftUI, UIDataDriver } from '@nativescript/swift-ui'
registerElement('swiftui', SwiftUI)
registerSwiftUI("sampleView", (view) =>
new UIDataDriver(SampleViewProvider.alloc().init(), view)
)
const App = () => {
const [count, setCount] = createSignal(0)
return <>
<actionbar title="Hello, SolidJS!"></actionbar>
<stacklayout>
<swiftui swiftId="sampleView" height="200" data={{count: count()}} on:swiftUIEvent={(evt) => setCount(evt.data.count)}/>
<label>You have taapped {count()} time{count() === 1 ? '' : 's'}</label>
{
// use 'on:___' instead of 'on___' for event handlers
// See https://github.com/SudoMaker/dominative-solid#event-handling for detail
}
<button class="-primary" on:tap={() => setCount(c => c + 1)}>Tap me!</button>
</stacklayout>
</>
}
const create = () => {
document.body.actionBarHidden = false
render(App, document.body)
return document
}
Application.run({ create })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment