{"id":11523,"date":"2014-06-24T14:51:00","date_gmt":"2014-06-24T14:51:00","guid":{"rendered":"https:\/\/viewmyprojects.com\/winwirewp\/?p=11523"},"modified":"2023-11-29T12:45:21","modified_gmt":"2023-11-29T12:45:21","slug":"hybrid-app-architecture-an-introduction","status":"publish","type":"post","link":"https:\/\/viewmyprojects.com\/winwirewp\/blog\/hybrid-app-architecture-an-introduction\/","title":{"rendered":"Hybrid App Architecture: An Introduction"},"content":{"rendered":"\n<p>Hybrid App Architecture:<br>\u2022 Web View<br>\u2022 Native Wrapper Integration<\/p>\n\n\n\n<p>Web View<br>All Web content\/app runs inside of Web Views within a Native Wrapper\/Container<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"221\" height=\"391\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View.webp\" alt=\"\" class=\"wp-image-18128\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View.webp 221w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View-170x300.webp 170w\" sizes=\"auto, (max-width: 221px) 100vw, 221px\" \/><\/figure>\n\n\n\n<p>Responsive Web Design: A Web design approach aimed at crafting web pages to provide an optimal viewing experience\u2014easy reading and navigation with a minimum of resizing, panning, and scrolling\u2014across a wide range of devices (from mobile phones to desktop computer monitors). Web content must be Responsive Design to display properly within each defined Web View. A Responsive Design web page displays properly within a the mobile device browser and desktop\/notepad browser without any change to the code base.<\/p>\n\n\n\n<p>Multiplatform Support<br>Leveraging Hybrid App for Multiplatform Support: This requires writing the container in Native mobile language. HTML5 Web components can be reused across all platforms without need to customize.<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 iOS: Objective C container + HTML5<br>\u2022 Android: Java Container + HTML5<br>\u2022 Windows: C# Container + HTML5<\/p>\n\n\n\n<p class=\"blog-detail-list\">Leveraging Hybrid App for Cross-platform Support: This requires writing the container in Cross-platform tool only ONCE. HTML5 Web components can be reused across all platforms without need to customize.<br>\u2022 Appcelerator + HTML5 OR Xamarin + HTML5<br>Multiple Form Factor Support: Responsive Web Design enables support across many form factors without a need to rewrite HTML5 code, namely,<\/p>\n\n\n\n<p class=\"blog-detail-list\">iPhone<br>\u2022 5: 1136\u00d7640<br>\u2022 4S: 640\u00d7960<br>iPad<br>\u2022 First &amp; second generations: 1024\u00d7768<br>\u2022 Third generation: 2048\u00d71536<br>iPad Mini 1024\u00d7768<\/p>\n\n\n\n<p class=\"blog-detail-list\">Android Phones &amp; Tablets<br>\u2022 Small screens: 426dp x 320dp<br>\u2022 Normal screens: 470dp x 320dp<br>\u2022 Large screens: 640dp x 480dp<br>\u2022 Extra-large screens: 960dp x 720dpNative Wrapper Integration<\/p>\n\n\n\n<p>Native: Performance Optimization<\/p>\n\n\n\n<p id=\"blog-detail-list\">Responsive Web Design<br>\u2022 Implement Device-Specific Functionality in Native Code (Speech Recognition, GPS, Accelerometer etc.)<br>o Faster performance<br>o Tighter feature integration with the device<br>o Access to the complete set of device-specific functionality<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 Minimize Graphics\/Animation on Web Content<br>o Graphic-intensive pages:Tend to render slowly in HTML, and also require bandwidth to be accessed from remote server<br>o Animation is optimized within native view<\/p>\n\n\n\n<p class=\"blog-detail-list\">\u2022 Optimize Data Access<br>o Remote content access for dynamically generated HTML pages<br>o Use Local HTML access for static content<\/p>\n\n\n\n<p>Native\/Web View Communication<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"489\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Native-or-Web-View-Communication-1024x489-1.webp\" alt=\"\" class=\"wp-image-18129\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Native-or-Web-View-Communication-1024x489-1.webp 1024w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Native-or-Web-View-Communication-1024x489-1-300x143.webp 300w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Native-or-Web-View-Communication-1024x489-1-768x367.webp 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>Direct Web View API Invocation<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"540\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Direct-Web-View-API-Invocation.webp\" alt=\"\" class=\"wp-image-18130\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Direct-Web-View-API-Invocation.webp 720w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Direct-Web-View-API-Invocation-300x225.webp 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<p>The first aspect of communication between the web view and the native aspect of a hybrid app is about the native part invoking methods on the web view.<\/p>\n\n\n\n<p class=\"blog-detail-list\">Open an URL: The native app invokes a method on the web view component to open and display the contents of a specified URL.<br>\u2022 Lets assume that the web view object is called \u2018webview\u2019.<br>\u2022 The native invokes a method on \u2018webview\u2019 as such: webview.openURL(\u2018url_to_open\u2019);<br>\u2022 The web view sends a request, fetches the response and displays the content.<\/p>\n\n\n\n<p class=\"blog-detail-list\">Navigation: The web view component provides API methods to perform navigation while visiting a web site. The native application invokes navigation methods on the web view<br>\u2022 webview.goForward(); \u2013 Allows the user to navigate forward in history<br>\u2022 webview.goBackward(); \u2013 Allows the user to navigate backward in history<br>\u2022 webview.canGoForward(); \u2013 Allows the user to test if forward navigation can be done<br>\u2022 webview.canGoBack(); \u2013 Allows the user to test if backward navigation can be done<\/p>\n\n\n\n<p>Web View to Native: Web View Event Captures<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"540\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View-Event-Captures.webp\" alt=\"\" class=\"wp-image-18131\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View-Event-Captures.webp 720w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Web-View-Event-Captures-300x225.webp 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<p class=\"blog-detail-list\">There are certain events generated from the web view that indicate the occurrence of an activity on the web view. These include:<br>\u2022 Web page beginning to load<br>\u2022 Web page loading done<br>\u2022 Single tap\/Double tap events on web view<br>\u2022 Swipe event on web view<br>\u2022 Click event on web view<\/p>\n\n\n\n<p class=\"blog-detail-list\">When these events are fired from the web view, the native app can capture these by means of event handlers so that an appropriate action can be executed. Typically, this is done on Appcelerator Studio or Titanium Studio using event listeners<br>\u2022 webview.addEventListener(\u2018load\u2019, function(){<br>\/\/event handler code goes here<br>});<br>On native platforms like iOS, this is done using delegate methods.<\/p>\n\n\n\n<p>JavaScript Injections<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"720\" height=\"540\" src=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/JavaScript-Injections.webp\" alt=\"\" class=\"wp-image-18133\" srcset=\"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/JavaScript-Injections.webp 720w, https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/JavaScript-Injections-300x225.webp 300w\" sizes=\"auto, (max-width: 720px) 100vw, 720px\" \/><\/figure>\n\n\n\n<p class=\"blog-detail-list\">\u2022 The native app can communicate with the web view to send messages using the first methodology we talked about earlier.<br>\u2022 However, there are scenarios when the native app needs to fetch or send custom data from\/to the web view respectively.<br>\u2022 This is because of the fact that the web page displayed in the web view usually consists of HTML and JavaScript.<br>\u2022 In order to change certain behavior of the web page being displayed in the web view, or to fetch data from the web view, which otherwise won\u2019t be accessible directly, the native app needs to be able to send or pull data pertaining to the web view\u2019s execution environment.<br>\u2022 Generally, the web view\u2019s execution environment runs JavaScript, which has its own scope, variables, methods, event listeners etc.<br>\u2022 Attempting to solve the issues outlined above requires injection of custom JavaScript into the web view\u2019s execution environment.<br>\u2022 This may also involve running a JavaScript code against the web view to fetch certain data pertaining to either the DOM or the web view\u2019s JavaScript scope.<br>\u2022 On Appcelerator Studio, this is achieved by invoking the method call \u2018evalJS\u2019 on the web view object.<br>\u2022 Using \u2018evalJS\u2019, JavaScript code can be injected to alter the web page\u2019s behavior, or the native app can send\/fetch custom data to\/from the web page.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Hybrid App Architecture:\u2022 Web View\u2022 Native Wrapper Integration Web ViewAll Web content\/app runs inside of Web Views within a Native Wrapper\/Container Responsive Web Design: A Web design approach aimed at crafting web pages to provide an optimal viewing experience\u2014easy reading and navigation with a minimum of resizing, panning, and scrolling\u2014across a wide range of devices&hellip; <a class=\"more-link\" href=\"https:\/\/viewmyprojects.com\/winwirewp\/blog\/hybrid-app-architecture-an-introduction\/\">Continue reading <span class=\"screen-reader-text\">Hybrid App Architecture: An Introduction<\/span><\/a><\/p>\n","protected":false},"author":48,"featured_media":16770,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_eb_attr":"","_uag_custom_page_level_css":"","footnotes":""},"categories":[1],"tags":[],"class_list":["post-11523","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-uncategorized","entry"],"acf":[],"featured_image_src":"https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp","author_info":{"display_name":"Amit","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/amit\/"},"views":4175,"uagb_featured_image_src":{"full":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp",800,440,false],"thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc-150x150.webp",150,150,true],"medium":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc-300x165.webp",300,165,true],"medium_large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc-768x422.webp",750,412,true],"large":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp",750,413,false],"1536x1536":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp",800,440,false],"2048x2048":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp",800,440,false],"post-thumbnail":["https:\/\/viewmyprojects.com\/winwirewp\/wp-content\/uploads\/2023\/11\/Hybrid-App-Arc.webp",800,440,false]},"uagb_author_info":{"display_name":"Amit","author_link":"https:\/\/viewmyprojects.com\/winwirewp\/author\/amit\/"},"uagb_comment_info":0,"uagb_excerpt":"Hybrid App Architecture:\u2022 Web View\u2022 Native Wrapper Integration Web ViewAll Web content\/app runs inside of Web Views within a Native Wrapper\/Container Responsive Web Design: A Web design approach aimed at crafting web pages to provide an optimal viewing experience\u2014easy reading and navigation with a minimum of resizing, panning, and scrolling\u2014across a wide range of devices&hellip;&hellip;","_links":{"self":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11523","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/users\/48"}],"replies":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/comments?post=11523"}],"version-history":[{"count":2,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11523\/revisions"}],"predecessor-version":[{"id":18134,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/posts\/11523\/revisions\/18134"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media\/16770"}],"wp:attachment":[{"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/media?parent=11523"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/categories?post=11523"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/viewmyprojects.com\/winwirewp\/wp-json\/wp\/v2\/tags?post=11523"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}