BoxViewClock Forms sample working in wasm
This commit is contained in:
parent
0f085717ad
commit
78528a0c87
|
@ -13,7 +13,7 @@ Expand that into this directory.
|
|||
## Build
|
||||
|
||||
```bash
|
||||
csc /nostdlib /target:library /r:managed/mscorlib.dll /r:managed/System.Runtime.dll /r:managed/Ooui.dll /out:managed/Ooui.Sample.dll ooui-sample.cs
|
||||
csc /nostdlib /target:library /r:managed/mscorlib.dll /r:managed/System.Runtime.dll /r:managed/Xamarin.Forms.Core.dll /r:managed/Ooui.dll /r:managed/Ooui.Forms.dll /out:managed/Ooui.Sample.dll ../Samples/ISample.cs ../Samples/BoxViewClockSample.cs ooui-sample.cs
|
||||
```
|
||||
|
||||
|
||||
|
|
|
@ -3,9 +3,8 @@ using Ooui;
|
|||
|
||||
public class Program
|
||||
{
|
||||
public static string Main (string a0, string a1)
|
||||
static Element GetButtonElement ()
|
||||
{
|
||||
try {
|
||||
var l = new Label { Text = "Hello" };
|
||||
var b = new Button ("Click Me");
|
||||
var e = new Div (new Div (l), b);
|
||||
|
@ -14,7 +13,20 @@ public class Program
|
|||
count++;
|
||||
b.Text = $"Clicked {count} times";
|
||||
};
|
||||
return e;
|
||||
}
|
||||
|
||||
static Element GetBoxViewClockElement ()
|
||||
{
|
||||
var s = new Samples.BoxViewClockSample ();
|
||||
return s.CreateElement ();
|
||||
}
|
||||
|
||||
public static string Main (string a0, string a1)
|
||||
{
|
||||
Xamarin.Forms.Forms.Init ();
|
||||
try {
|
||||
var e = GetBoxViewClockElement ();
|
||||
UI.SetGlobalElement ("main", e);
|
||||
return e.ToString ();
|
||||
}
|
||||
|
|
|
@ -37,6 +37,7 @@
|
|||
"System.Threading.Tasks.dll",
|
||||
"System.Reflection.dll",
|
||||
"System.Reflection.Extensions.dll",
|
||||
"System.Resources.ResourceManager.dll",
|
||||
"System.Runtime.dll",
|
||||
"System.Runtime.Extensions.dll",
|
||||
"System.Runtime.Serialization.dll",
|
||||
|
@ -48,6 +49,7 @@
|
|||
"Xamarin.Forms.Platform.dll",
|
||||
"Xamarin.Forms.Xaml.dll",
|
||||
"Ooui.dll",
|
||||
"Ooui.Forms.dll",
|
||||
mainAsmName + ".dll"
|
||||
];
|
||||
oouiWasm (mainAsmName, "", "Program", "Main", assemblies);
|
||||
|
|
|
@ -44,7 +44,7 @@ namespace Ooui
|
|||
}
|
||||
}
|
||||
|
||||
void QueueMessageLocked (Message message)
|
||||
protected void QueueMessageLocked (Message message)
|
||||
{
|
||||
//
|
||||
// Make sure all the referenced objects have been created
|
||||
|
|
|
@ -18,38 +18,43 @@ namespace Ooui
|
|||
|
||||
protected override void QueueMessage (Message message)
|
||||
{
|
||||
base.QueueMessage (message);
|
||||
TransmitQueuedMessages ();
|
||||
}
|
||||
|
||||
void TransmitQueuedMessages ()
|
||||
{
|
||||
//
|
||||
// Dequeue as many messages as we can
|
||||
//
|
||||
var messagesToSend = new List<Message> ();
|
||||
lock (queuedMessages) {
|
||||
messagesToSend.AddRange (queuedMessages);
|
||||
QueueMessageLocked (message);
|
||||
var max = 1;
|
||||
var i = 0;
|
||||
while (i < queuedMessages.Count) {
|
||||
TransmitQueuedMessagesLocked (queuedMessages, i, max);
|
||||
i += max;
|
||||
}
|
||||
// WebAssembly.Runtime.InvokeJS("console.log('TRANSMITTED'," + queuedMessages.Count + ")");
|
||||
queuedMessages.Clear ();
|
||||
}
|
||||
}
|
||||
|
||||
void TransmitQueuedMessagesLocked (List<Message> messagesToSend, int startIndex, int max)
|
||||
{
|
||||
if (messagesToSend.Count == 0)
|
||||
return;
|
||||
|
||||
//
|
||||
// Now actually send the messages
|
||||
//
|
||||
var sb = new StringBuilder ();
|
||||
var sb = new System.IO.StringWriter ();
|
||||
sb.Write ("__oouiReceiveMessages(\"");
|
||||
sb.Write (id);
|
||||
sb.Write ("\",");
|
||||
sb.Write ("[");
|
||||
var head = "";
|
||||
sb.Append ("[");
|
||||
foreach (var m in messagesToSend) {
|
||||
sb.Append (head);
|
||||
sb.Append (m.ToJson ());
|
||||
int n = 0;
|
||||
for (var i = startIndex; i < messagesToSend.Count && n < max; i++, n++) {
|
||||
sb.Write (head);
|
||||
messagesToSend[i].WriteJson (sb);
|
||||
head = ",";
|
||||
}
|
||||
sb.Append ("]");
|
||||
var json = sb.ToString ();
|
||||
WebAssembly.Runtime.InvokeJS ("__oouiReceiveMessages(\"" + id + "\", " + json + ")");
|
||||
sb.Write ("])");
|
||||
var jsonp = sb.ToString ();
|
||||
// WebAssembly.Runtime.InvokeJS("console.log('TRANSMIT',"+n+")");
|
||||
WebAssembly.Runtime.InvokeJS (jsonp);
|
||||
}
|
||||
|
||||
public void ReceiveMessageJson (string json)
|
||||
|
|
Loading…
Reference in New Issue