BoxViewClock Forms sample working in wasm

This commit is contained in:
Frank A. Krueger 2018-03-09 23:12:07 -08:00
parent 0f085717ad
commit 78528a0c87
No known key found for this signature in database
GPG Key ID: 0471C67474FFE664
5 changed files with 49 additions and 30 deletions

View File

@ -13,7 +13,7 @@ Expand that into this directory.
## Build ## Build
```bash ```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
``` ```

View File

@ -3,9 +3,8 @@ using Ooui;
public class Program public class Program
{ {
public static string Main (string a0, string a1) static Element GetButtonElement ()
{ {
try {
var l = new Label { Text = "Hello" }; var l = new Label { Text = "Hello" };
var b = new Button ("Click Me"); var b = new Button ("Click Me");
var e = new Div (new Div (l), b); var e = new Div (new Div (l), b);
@ -14,7 +13,20 @@ public class Program
count++; count++;
b.Text = $"Clicked {count} times"; 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); UI.SetGlobalElement ("main", e);
return e.ToString (); return e.ToString ();
} }

View File

@ -37,6 +37,7 @@
"System.Threading.Tasks.dll", "System.Threading.Tasks.dll",
"System.Reflection.dll", "System.Reflection.dll",
"System.Reflection.Extensions.dll", "System.Reflection.Extensions.dll",
"System.Resources.ResourceManager.dll",
"System.Runtime.dll", "System.Runtime.dll",
"System.Runtime.Extensions.dll", "System.Runtime.Extensions.dll",
"System.Runtime.Serialization.dll", "System.Runtime.Serialization.dll",
@ -48,6 +49,7 @@
"Xamarin.Forms.Platform.dll", "Xamarin.Forms.Platform.dll",
"Xamarin.Forms.Xaml.dll", "Xamarin.Forms.Xaml.dll",
"Ooui.dll", "Ooui.dll",
"Ooui.Forms.dll",
mainAsmName + ".dll" mainAsmName + ".dll"
]; ];
oouiWasm (mainAsmName, "", "Program", "Main", assemblies); oouiWasm (mainAsmName, "", "Program", "Main", assemblies);

View File

@ -44,7 +44,7 @@ namespace Ooui
} }
} }
void QueueMessageLocked (Message message) protected void QueueMessageLocked (Message message)
{ {
// //
// Make sure all the referenced objects have been created // Make sure all the referenced objects have been created

View File

@ -18,38 +18,43 @@ namespace Ooui
protected override void QueueMessage (Message message) 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) { 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 (); queuedMessages.Clear ();
} }
}
void TransmitQueuedMessagesLocked (List<Message> messagesToSend, int startIndex, int max)
{
if (messagesToSend.Count == 0) if (messagesToSend.Count == 0)
return; return;
// //
// Now actually send the messages // 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 = ""; var head = "";
sb.Append ("["); int n = 0;
foreach (var m in messagesToSend) { for (var i = startIndex; i < messagesToSend.Count && n < max; i++, n++) {
sb.Append (head); sb.Write (head);
sb.Append (m.ToJson ()); messagesToSend[i].WriteJson (sb);
head = ","; head = ",";
} }
sb.Append ("]"); sb.Write ("])");
var json = sb.ToString (); var jsonp = sb.ToString ();
WebAssembly.Runtime.InvokeJS ("__oouiReceiveMessages(\"" + id + "\", " + json + ")"); // WebAssembly.Runtime.InvokeJS("console.log('TRANSMIT',"+n+")");
WebAssembly.Runtime.InvokeJS (jsonp);
} }
public void ReceiveMessageJson (string json) public void ReceiveMessageJson (string json)