Skip to content

Instantly share code, notes, and snippets.

@rylax
Last active April 11, 2020 20:56
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 rylax/06fb1da2b8f118cd5a978fbb013243d1 to your computer and use it in GitHub Desktop.
Save rylax/06fb1da2b8f118cd5a978fbb013243d1 to your computer and use it in GitHub Desktop.
Display Alert with Swift [Bug]
using Uno;
using Uno.Collections;
using Fuse;
using Fuse.Scripting;
using Uno.UX;
using Uno.Compiler.ExportTargetInterop;
[ForeignInclude(Language.ObjC, "@(Project.Name)-Swift.h")]
public class HelloSwift : NativeModule
{
[Foreign(Language.ObjC)]
public static void hello()
@{
HelloSwiftWorld* x = [[HelloSwiftWorld alloc] init];
[x hello];
@}
}
import Foundation
import UIKit
public class HelloSwiftWorld: NSObject {
public func hello() {
let alert = UIAlertController(title: "Did you bring your towel?", message: "It's recommended you bring your towel before continuing.", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "Yes", style: .default, handler: nil))
alert.addAction(UIAlertAction(title: "No", style: .cancel, handler: nil))
self.present(alert, animated: true)
}
}
<App>
<DockPanel>
<StatusBarBackground Dock="Top" />
<BottomBarBackground Dock="Bottom" />
<HelloSwift ux:Global="HelloSwift" />
<JavaScript>
var HelloSwift = require("HelloSwift")
function button_pressed_fromSwift() {
HelloSwift.hello();
}
module.exports = {
button_pressed_fromSwift: button_pressed_fromSwift
};
</JavaScript>
<StackPanel Margin="0,50,0,0">
<Button Text="From Swift!" Clicked="{button_pressed_fromSwift}" />
</StackPanel>
</DockPanel>
</App>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment