Multi-terminal cross-platform solution
Through a multi-end cross-platform solution, the integration of React Native and React Native Web is used to realize the development of the same set of code base, solve the H5 page rendering problem, reduce development costs and complexity, improve user experience and efficiency, and realize The cost reduction and efficiency enhancement effect of cross-platform development.
Patent Information
- Application Number
- CN202410993808.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-07-23
- Publication Date
- 2024-11-22
AI Technical Summary
Existing cross-platform development technologies, especially ReactNative, are difficult to effectively solve the rendering problem of H5 pages, resulting in low development efficiency and user experience, and the need to develop both ends at the same time, which increases the workload and cost.
Adopt multi-end cross-platform solutions, including business code separation, multi-module entry packaging, native rendered bridge code adaptation, basic business adaptation and packaging product access, and realize the same set of code base through the integration of React Native and React Native Web. The development of Vue code generates related js files, provides AHRNBannerView code, performs native rendering bridge and scroll view adaptation, reducing development costs and complexity.
It realizes the use of the same set of code for development on the mobile and web side, which reduces the development workload and cost, improves the user experience and application response speed, reduces the communication cost and testing workload of the development team, and provides a more consistent interface and Interactive experience.
Smart Images

Figure CN119002995A_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of multi-terminal cross-platform technology, and specifically provides a multi-terminal cross-platform solution. Background Art
[0002] The mission of cross-platform development is to prioritize both development performance and user experience. Specific implementation scenarios present trade-offs between user experience and R&D efficiency. Before the emergence of cross-platform technologies, the primary front-end technology stacks were iOS and Android native development and web development. The former offers a better user experience, but due to the fragmented nature of the technology and the need for simultaneous development on multiple platforms, the workload doubles per platform. The latter allows one person to develop for multiple platforms, saving costs, but lacks a satisfactory user experience due to web hosting requirements. Most cross-platform mobile app solutions typically utilize React Native to generate both iOS and Android platforms.
[0003] However, ReactNative allows developers to use JavaScript and React to write code and build user interfaces through native components, thus achieving cross-platform development while maintaining native performance. However, for the rendering of H5 pages, the solution based on complete ReactNative development cannot directly solve the problem of generating H5 pages with mixed development content. Currently, many developers have adopted a hybrid development strategy, that is, using ReactNative for native interface development and using WebView or other technologies to render H5 pages. Although this method can reduce development costs to a certain extent, since both ends need to be developed and the bridging native class cannot directly generate pages, the development efficiency and user experience are low, so it needs to be improved and optimized. Summary of the Invention
[0004] The purpose of the present invention is to provide a multi-terminal cross-platform solution to solve the problems raised in the above background technology.
[0005] In order to achieve the above-mentioned purpose, the present invention provides the following technical solutions: a multi-terminal cross-platform solution, including business code separation, multi-module entry packaging, native rendering bridge code adaptation, basic business adaptation, special compatibility adaptation and packaged product access.
[0006] Preferably, the adaptation methods of the native rendering bridge code adaptation, basic business adaptation and special compatibility adaptation are:
[0007] S1, by:
[0008] if(Platform.OS=='web'){return <view / >
[0009] }else{
[0010] .........}Judge the basic platform;
[0011] S2, through react-native code:
[0012] <View nativeID='che168ElOneStopImgAnimation'> Make the vue code generate related js files;
[0013] S3, js file first replaces the rn-web key points by id replacement method, and then hangs the window through interactive adoption method:
[0014] Vue.prototype.$eventBus=new Vue(); / / Register eventBus new Vue({
[0015] el:'#che168ElOneStopImgAnimation',
[0016] render:h=>h(index)
[0017] });
[0018] S4, through the provided reactnative code class AHRNBannerView code, enables reactnative to achieve the same effect on multiple platforms, completing the bridge code adaptation of Autohome's native rendering;
[0019] S5: Use the same class name and method name to convert in Util.js, so that the two projects respectively introduce the original React Native plug-in package and the rewritten usedcar-web-lib directory file to achieve docking and complete basic business adaptation;
[0020] In S6, the h5 side adds the {position:'fixed'} method to ensure the position of the pop-up window. It can also be implemented through React Native to complete the adaptation of the page pop-up window code.
[0021] S7, by using the view in ReactNative-web to listen to the scroll property of the document, the scroll view adaptation is completed, which is different from the scroll view of ReactNative.
[0022] Preferably, the business code separation method adopts two independent sets of git management project files, and the Core business code is managed in two independent git repositories to separate the independent features of the two groups of platforms.
[0023] Preferably, the multi-module entry packaging is implemented by using webpack technology, and multiple projects are packaged dynamically according to folders at the same time, their respective configurations are introduced, and static js is uploaded.
[0024] Preferably, the multi-module entry packaging method is:
[0025] Step 1: Introduce the dev debugging entry through routerconfig.js;
[0026] Step 2: Process static file uploads through upload.js;
[0027] Step 3: Design an independent directory through Entry, and then introduce the package through the file directory structure;
[0028] Step 4: Dynamically introduce each business through the routerConfigProd.js configuration and the customized MyConfigPlugin.js;
[0029] Step 5: Inject title, introduce independent id of div and preload js through configuration file to complete dynamic packaging of multiple projects.
[0030] Preferably, by adopting the same-name class AHRNBannerView to ensure the carousel image by itself, dynamically introducing CSS styles and implementing swiper through react native, these three feasible adaptation solutions can enable react native to achieve the same effect on multiple platforms.
[0031] Preferably, the packaged product is accessed in the following manner:
[0032] A1: The car selection control is provided to the host through the window mounting method;
[0033] A2: After the user operation is completed, the data is returned through callback;
[0034] A3: Data is packaged using react-native-web, and the packaged products are js files and html files.
[0035] Preferably, the basic business adaptation is divided into business processing and UI categories. Taking positioning as an example, the method of interacting with the native bridge on the APP side to obtain native positioning is:
[0036] B1, using the native positioning API of Android or iOS;
[0037] B2, implement a JavaScript callable interface in the native application, which encapsulates the positioning function;
[0038] B3, in the JavaScript code, call the native positioning interface through JSBridge;
[0039] B4: The native end passes the positioning results to JavaScript, which performs corresponding processing to complete the positioning.
[0040] Preferably, the location information is obtained on the H5 side through (window as any).navigator.geolocation.getCurrentPosition((position:any).
[0041] Preferably, the business code separation method adopts ts development to reduce the risk of field errors.
[0042] The beneficial effects of the present invention are as follows:
[0043] 1. This invention integrates React Native and React Native Web to achieve development on both mobile and web ends using the same code base, thereby greatly reducing the development workload. Compared with native development + Web development, the workload is reduced by 2 people; compared with separate React Native + Web development, the workload is also reduced by 1 person. This technology selection allows the development of all three ends to be completed by only one person, greatly reducing development costs and workload.
[0044] 2. This invention uses React Native Web technology to transform existing Web applications, so that React Native rendering is used on mobile terminals, which has better performance and user experience than pure WebView rendering. This transformation not only improves the responsiveness and fluency of the application, but also makes the interface and interaction between the mobile terminal and the Web terminal more consistent, enhancing the overall user experience.
[0045] 3. The present invention adopts a unified code base and technology stack, which reduces the communication costs between development teams and improves development efficiency. At the same time, due to the reduction in code volume and complexity, it also reduces the testing workload of the testing team on the business. This cross-platform technology selection not only achieves the goal of reducing costs and increasing efficiency, but also provides users with a better product experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] Figure 1 The invention is adapted to reactnative page packaging IOS, Android generation package environment screenshot;
[0047] Figure 2 This is the screenshot of the H5 adaptation generated by the page after the present invention adopts reactnative-web;
[0048] Figure 3 This is a screenshot of the H5 multi-entry packaging of the present invention;
[0049] Figure 4 This is a screenshot of the dynamic packaging of the present invention;
[0050] Figure 5 This is a screenshot of the react native code class AHRNBannerView code of the present invention;
[0051] Figure 6 This is a screenshot of the bridge code adaptation for the native rendering of Autohome of the present invention;
[0052] Figure 7 This is a screenshot of the basic business adaptation of the present invention;
[0053] Figure 8 This is a screenshot of the reactnative-web package of the present invention;
[0054] Figure 9 Screenshot of the pop-up window code adaptation for the present invention page;
[0055] Figure 10 Adapting screenshots for the scroll view of the present invention. DETAILED DESCRIPTION
[0056] The following will clearly and completely describe the technical solutions in the embodiments of the present invention in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts are within the scope of protection of the present invention.
[0057] like Figures 1 to 10 As shown, an embodiment of the present invention provides a multi-terminal cross-platform solution, including business code separation, multi-module entry packaging, native rendering bridge code adaptation, basic business adaptation, special compatibility adaptation and packaged product access.
[0058] Among them, the adaptation methods for native rendering bridge code adaptation, basic business adaptation, and special compatibility adaptation are as follows:
[0059] S1, by:
[0060] if(Platform.OS=='web'){return <view / >
[0061] }else{
[0062] .........}Judge the basic platform;
[0063] S2, through react-native code:
[0064] <View nativeID='che168ElOneStopImgAnimation'> Make the vue code generate related js files;
[0065] S3, js file first replaces the rn-web key points by id replacement method, and then hangs the window through interactive adoption method:
[0066] Vue.prototype.$eventBus=new Vue(); / / Register eventBus new Vue({
[0067] el:'#che168ElOneStopImgAnimation',
[0068] render:h=>h(index)
[0069] });
[0070] S4, through the provided reactnative code class AHRNBannerView code, enables reactnative to achieve the same effect on multiple platforms, completing the bridge code adaptation of Autohome's native rendering;
[0071] S5: Use the same class name and method name to convert in Util.js, so that the two projects respectively introduce the original React Native plug-in package and the rewritten usedcar-web-lib directory file to achieve docking and complete basic business adaptation;
[0072] like Figure 5 As shown, some of the complex React Native controls in the Autohome APP are implemented natively and cannot be directly converted using React Native-Web.
[0073] In S6, the h5 side adds the {position:'fixed'} method to ensure the position of the pop-up window. It can also be implemented through React Native to complete the adaptation of the page pop-up window code.
[0074] like Figure 9As shown in the figure, by adding the {position:'fixed'} method, the pop-up window will remain in the same position on the screen, ensuring that users can always see and interact with the pop-up window. React Native uses native UI components to render the interface, so the display and performance of the pop-up window are closer to native applications and are smoother and more efficient than pop-ups on the Web.
[0075] S7, by using the view in ReactNative-web to listen to the scroll property of the document, the scroll view adaptation is completed, which is different from the scroll view of ReactNative.
[0076] like Figure 10 As shown, by listening to the document.scroll event, you can more easily implement interactions and animations that are compatible with the scrolling behavior in web browsers. This helps maintain the consistency and user experience of React Native web applications in the web environment.
[0077] The integration of React Native and React Native Web enables development on both mobile and web platforms using the same code base, significantly reducing development workload. Compared to native development plus web development, this reduces the workload by two people, and compared to separate React Native and web development, it reduces the workload by one person. This technology selection allows development on all three platforms to be completed by a single person, significantly reducing development costs and workload.
[0078] Through React Native Web technology, existing web applications have been transformed so that React Native rendering can be used on mobile devices, which has better performance and user experience than pure WebView rendering. This transformation not only improves the responsiveness and smoothness of the application, but also makes the interface and interaction between mobile and web devices more consistent, enhancing the overall user experience.
[0079] The use of a unified code base and technology stack reduces communication costs between development teams and improves development efficiency. At the same time, the reduced code volume and complexity also reduces the testing workload of the testing team on the business. This cross-platform technology selection not only achieves the goal of reducing costs and increasing efficiency, but also provides users with a better product experience.
[0080] Among them, the business code separation method uses two independent sets of git management project files, manages the Core business code in two independent git repositories, and separates the independent features of the two groups of platforms.
[0081] like Figure 1 and Figure 2 As shown, the core code can be embedded as a submodule in the project file of the platform-specific code, so that the same business logic can be shared on different platforms. The same business code is used on both ends. This architecture can better adapt to multi-terminal environments and reduce the workload of repeated development.
[0082] Among them, multi-module entry packaging is packaged using webpack technology, and multiple projects are packaged dynamically according to the folder, and their respective configurations are introduced and static js is uploaded to achieve it.
[0083] Among them, the multi-module entry packaging method is:
[0084] Step 1: Introduce the dev debugging entry through routerconfig.js;
[0085] Step 2: Process static file uploads through upload.js;
[0086] Step 3: Design an independent directory through Entry, and then introduce the package through the file directory structure;
[0087] Step 4: Dynamically introduce each business through the routerConfigProd.js configuration and the customized MyConfigPlugin.js;
[0088] Step 5: Inject title, introduce independent id of div and preload js through configuration file to complete dynamic packaging of multiple projects.
[0089] like Figure 3 and Figure 4 As shown, the file directory structure dynamically generates entry points to support the simultaneous packaging of multiple projects. The packaging behavior can be easily adjusted through routerconfig.js and routerConfigProd.js without modifying the source code, which improves flexibility.
[0090] Among them, by adopting the class AHRNBannerView of the same name to ensure the carousel image by itself, dynamically introducing CSS styles and implementing swiper through reactnative, these three feasible adaptation solutions can enable reactnative to achieve the same effect on multiple platforms.
[0091] like Figure 6 As shown, the three solutions of ensuring the carousel image by the class AHRNBannerView of the same name, dynamically introducing CSS styles, and implementing swiper through react-native are all feasible adaptation solutions. There is no superiority or inferiority, and different adaptation methods can be adopted according to different business forms.
[0092] Among them, the way to access the packaged product is:
[0093] A1: The car selection control is provided to the host through the window mounting method;
[0094] A2: After the user operation is completed, the data is returned through callback;
[0095] A3: Data is packaged using react-native-web, and the packaged products are js files and html files.
[0096] like Figure 8 As shown, the car selection control is provided to the host side through the mounting method on the window. After the user operation is completed, the data is returned through the callback. This ensures that the compiled product of reactnative-web can be mixed with js environments such as Vue for development, making it easier for old projects to transition to reactnative-web development.
[0097] Among them, basic business adaptation is divided into business processing and UI categories. Taking positioning as an example, the way to interact with the native bridge on the APP side to obtain native positioning is:
[0098] B1, using the native positioning API of Android or iOS;
[0099] B2, implement a JavaScript callable interface in the native application, which encapsulates the positioning function;
[0100] B3, in the JavaScript code, call the native positioning interface through JSBridge;
[0101] B4: The native end passes the positioning results to JavaScript, which performs corresponding processing to complete the positioning.
[0102] like Figure 7 As shown in the figure, the two projects respectively introduce the original React Native plug-in package and the rewritten usedcar-web-lib directory file to achieve docking.
[0103] Among them, on the H5 side, the positioning information is obtained through (window as any).navigator.geolocation.getCurrentPosition((position:any).
[0104] Among them, the business code separation method adopts ts development to reduce the risk of field errors.
[0105] It should be noted that, in this document, relational terms such as first and second, etc., are used only to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any actual relationship or order between these entities or operations. Moreover, the terms "comprises," "comprising," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements includes not only those elements but also other elements not explicitly listed, or elements inherent to such process, method, article, or apparatus.
[0106] While embodiments of the present invention have been shown and described, it will be appreciated by those skilled in the art that various changes, modifications, substitutions, and variations may be made to these embodiments without departing from the principles and spirit of the invention, and that the scope of the invention is defined by the appended claims and their equivalents.
Claims
1. A multi-terminal cross-platform solution, characterized by: It includes business code separation methods, multi-module entry packaging, bridge code adaptation for native rendering, basic business adaptation, special compatibility adaptation and packaged product access.
2. A multi-terminal cross-platform solution according to claim 1, characterized in that: The adaptation methods of the native rendering bridge code adaptation, basic business adaptation and special compatibility adaptation are: S1, by: if(Platform.OS=='web'){return <view / > }else{ .........}Judge the basic platform; S2, through reactnative code: <View nativeID='che168ElOneStopImgAnimation'> Make vue code generate related js files; S3, js file first replaces the rn-web key points by id replacement method, and then hangs the window through interactive adoption method: Vue.prototype.$eventBus=new Vue(); / / Register eventBus new Vue({ el:'#che168ElOneStopImgAnimation', render:h=>h(index) }); S4, through the provided reactnative code class AHRNBannerView code, reactnative multi-platform achieves the same effect and completes the bridge code adaptation of Autohome native rendering; As shown S5, use the same class name and method name to convert in Uti l.js, so that the two projects respectively introduce the original React Native plug-in package and the rewritten usedcar-web-lib directory file to achieve docking and complete basic business adaptation; S6, h5 end adds the {position:'fixed'} method to ensure the pop-up window position, and can also be implemented through React Native to complete the adaptation of the page pop-up window code; S7, by using the view in ReactNative-web to listen to the scroll l attribute of the document, the scroll view adaptation is completed, which is different from the scroll view of ReactNative.
3. A multi-terminal cross-platform solution according to claim 1, characterized in that: The business code separation method uses two sets of independent git management project files, manages the Core business code in two independent git repositories, and separates the independent features of the two groups of platforms.
4. A multi-terminal cross-platform solution according to claim 1, characterized in that: The multi-module entry packaging is packaged using webpack technology, and multiple projects are packaged dynamically according to folders at the same time, their respective configurations are introduced, and static js is uploaded to achieve it.
5. A multi-terminal cross-platform solution according to claim 4, characterized in that: The multi-module entry packaging method is: Step 1: Introduce the dev debugging entry through routerconfig.js; Step 2: Process static file uploads through upload.js; Step 3, design an independent directory through Entry, and then introduce the package through the file directory structure; Step 4: Dynamically introduce each business through routerConfigProd.js configuration and customized MyConfigPlugin.js; Step 5, inject title, inject independent id of introduced div and inject preloaded js through configuration file to complete dynamic packaging of multiple projects.
6. A multi-terminal cross-platform solution according to claim 2, characterized in that: By adopting the same-name class AHRNBannerView to ensure the carousel image by itself, dynamically introducing css styles and implementing swiper through reactnative, these three adaptation feasible solutions can make reactnative achieve the same effect on multiple platforms.
7. A multi-terminal cross-platform solution according to claim 1, characterized in that: The packaging product access method is: A1, the car selection control is provided to the host end through the mounting method on the window; A2: After the user operation is completed, data is returned through call back; A3: Data is packaged through reactnative-web, and the packaged products are js files and html files.
8. A multi-terminal cross-platform solution according to claim 1, characterized in that: The basic business adaptation is divided into business processing and UI. Taking positioning as an example, the way to obtain native positioning by interacting with the native bridge on the APP side is: B1, using the native positioning API of Android or iOS; B2, implement a JavaScript callable interface in the native application, which encapsulates the positioning function; B3, in the JavaScript code, call the native positioning interface through JSBridge; B4, the native end passes the positioning result to JavaScript, and JavaScript performs corresponding processing to complete the positioning.
9. A multi-terminal cross-platform solution according to claim 8, characterized in that: On the H5 side, (window as any).navigator.geolocation.getCurrentPosition((position:any) to interact with the native bridge to obtain the native positioning.
10. A multi-terminal cross-platform solution according to claim 3, characterized in that: The business code separation method adopts ts development to reduce the risk of field errors.
