Add preloading features (#1377)
authorJay Cho <chojoong@gmail.com>
Tue, 11 Feb 2020 02:27:53 +0000 (11:27 +0900)
committerGitHub <noreply@github.com>
Tue, 11 Feb 2020 02:27:53 +0000 (11:27 +0900)
src/ElmSharp/ElmSharp/Elementary.cs
src/ElmSharp/ElmSharp/PreloadedWindow.cs
src/ElmSharp/ElmSharp/Window.cs

index b12d5f4..4143ab4 100644 (file)
@@ -207,7 +207,8 @@ namespace ElmSharp
         /// <since_tizen> preview </since_tizen>
         public static void Initialize()
         {
-            Interop.Elementary.elm_init(0, null);
+            if (!Window.IsPreloaded)
+                Interop.Elementary.elm_init(0, null);
         }
 
         /// <summary>
@@ -235,7 +236,7 @@ namespace ElmSharp
         [EditorBrowsable(EditorBrowsableState.Never)]
         public static void ThemeOverlay()
         {
-            if (File.Exists(_themeFilePath))
+            if (!Window.IsPreloaded && File.Exists(_themeFilePath))
             {
                 AddThemeOverlay(_themeFilePath);
             }
index aafbb4a..64c4317 100644 (file)
@@ -25,6 +25,10 @@ namespace ElmSharp
             s_precreated = this;
             if (useBaseLayout)
                 InitializeBaseLayout();
+            WarmupWidgets();
+            BackButtonPressed += DummyHandler;
+            BackButtonPressed -= DummyHandler;
+            void DummyHandler(object sender, System.EventArgs e) { }
         }
 
         public Layout BaseLayout
@@ -46,6 +50,25 @@ namespace ElmSharp
             conformant.SetContent(BaseLayout);
         }
 
+        public void WarmupWidgets()
+        {
+            new Entry(this).Unrealize();
+            new Scroller(this).Unrealize();
+            new Box(this).Unrealize();
+            new Label(this).Unrealize();
+            new GenList(this).Unrealize();
+            new Button(this).Unrealize();
+            new Check(this).Unrealize();
+            new Naviframe(this).Unrealize();
+            new Slider(this).Unrealize();
+            new Spinner(this).Unrealize();
+            new ProgressBar(this).Unrealize();
+            new GestureLayer(this).Unrealize();
+            new Polygon(this).Unrealize();
+            new Image(this).Unrealize();
+            //TODO: Consider to call Image.LoadAsync()
+        }
+
         public static PreloadedWindow GetInstance()
         {
             var instance = s_precreated;
index 270078e..e57f43f 100644 (file)
@@ -1079,6 +1079,8 @@ namespace ElmSharp
             }
         }
 
+        internal static bool IsPreloaded { get; private set; }
+
         /// <summary>
         /// Creates a socket to provide the service for the Plug widget.
         /// </summary>
@@ -1302,6 +1304,7 @@ namespace ElmSharp
             Elementary.Initialize();
             Elementary.ThemeOverlay();
             _ = new PreloadedWindow();
+            IsPreloaded = true;
         }
 
         /// <summary>