CN106843850B - Method and device for transferring Native objects between read Native components - Google Patents
Method and device for transferring Native objects between read Native components Download PDFInfo
- Publication number
- CN106843850B CN106843850B CN201611234768.0A CN201611234768A CN106843850B CN 106843850 B CN106843850 B CN 106843850B CN 201611234768 A CN201611234768 A CN 201611234768A CN 106843850 B CN106843850 B CN 106843850B
- Authority
- CN
- China
- Prior art keywords
- native
- data management
- memory data
- boxed
- management module
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/44—Arrangements for executing specific programs
- G06F9/448—Execution paradigms, e.g. implementations of programming paradigms
- G06F9/4488—Object-oriented
Abstract
The invention provides a method and a device for transferring Native objects between read Native components. The method for transferring Native objects between real Native components comprises the following steps: the memory data management module packages a Native object to be boxed of the first read Native component into a universal type boxing object; the first read Native component sends the boxed object to a javascript business logic module; a second read Native component receives the boxing object forwarded by the javascript service logic module; and the internal memory data management module unpacks the boxed object to obtain the native object, and transmits the native object of any type through the javascript.
Description
Technical Field
The invention relates to the technical field of real Native, in particular to a method and a device for transferring Native objects between real Native components.
Background
The fact Native is a technology allowing a developer to build a Native App by using a front-end language, and the principle is to encapsulate a Native UI component to achieve the purpose of using javascript to allocate the Native UI component to construct an interface. The built native App has the flexibility of a web App and has the advantage of good interaction experience.
In actual development by using real Native, data is often required to be transmitted between real Native components/APIs through javascript, that is, one of the real Native components/APIs transmits data to javascript, and the javascript transmits the data to the other real Native component/API after being subjected to service processing for use. The general types of the data are integer type, floating point type, character string, array, dictionary and the like, and the data of the types can be directly transmitted between javascript and real Native components/APIs. However, the ReactNative framework cannot convert some special native objects such as image objects, custom models and the like into objects recognizable by javascript, and only can process the memory addresses of the native objects as 16-system numbers or character strings; another problem is how the lifecycle of a native object is managed after the object is handed to javascript. Therefore, a method and an apparatus for transferring Native objects between real Native components are needed to solve the above technical problems in the prior art.
Disclosure of Invention
The invention provides a method and a device for transferring Native objects among real Native components, wherein any type of Native object is transferred through javascript.
The technical scheme adopted by the invention is as follows: a method of transferring Native objects between read Native components, comprising: the memory data management module packages a Native object to be boxed of the first read Native component into a universal type boxing object; the first read Native component sends the boxed object to a javascript business logic module; a second read Native component receives the boxing object forwarded by the javascript service logic module; and the internal memory data management module carries out unpacking operation on the boxed object to obtain the native object.
Preferably, after the Native object to be boxed of the first read Native component is packaged into a universal type of boxing object by the memory data management module, the method further includes: and saving the strong reference of the native object to be boxed.
Preferably, after saving the strong reference of the native object to be boxed, the method further comprises: the javascript service logic module sends a release instruction to the memory data management component; and the memory data management component calls a removal reference interface of the memory data management module based on the release instruction to remove the strong reference of the native object to be boxed.
Preferably, before the Native object to be boxed of the first read Native component is packaged into a universal type of boxed object by the memory data management module, the method further includes: the first read Native component calls a packing method of the memory data management module; correspondingly, before the memory data management module unpacks the packed object and obtains the native object, the method further includes: and the second real Native component calls an unpacking method of the memory data management module.
The invention also provides a device for transferring Native objects between the read Native components, which comprises: the memory data management module is used for packaging the Native object to be boxed of the first read Native component into a universal type boxing object; the first read Native component is used for sending the boxed object to a javascript business logic module; the second read Native component is used for receiving the boxing object forwarded by the javascript service logic module; the memory data management module is further configured to perform unpacking operation on the packed object to obtain the native object.
Preferably, the data management and storage module is further configured to: and saving the strong reference of the native object to be boxed.
Preferably, the apparatus further comprises a memory data management component, configured to: and under the condition that the javascript business logic module sends a release instruction to the memory data management module, the memory data management module calls a removal reference interface of the memory data management module based on the release instruction to remove the strong reference of the native object to be boxed.
Preferably, the first React Native component is further configured to: calling a boxing method of the memory data management module before the memory data management module packages a Native object to be boxed of the first read Native component into a universal type boxing object; accordingly, the second read Native component is further configured to: and the second ReactNative component calls an unpacking method of the memory data management module before the memory data management module unpacks the boxed object to obtain the native object.
By adopting the technical scheme, the invention at least has the following effects:
by adopting the method for transmitting the native objects among the Reactnative components, any type of native object can be transmitted through javascript.
Drawings
FIG. 1 is a flow chart of a method for transferring Native objects between real Native components according to a first embodiment of the present invention;
FIG. 2 is a flowchart of a method for transferring Native objects between real Native components according to a second embodiment of the present invention;
fig. 3 is a block diagram of a memory data management module in a device for transferring Native objects between read Native components according to a fourth embodiment of the present invention.
Detailed Description
To further explain the technical means and effects of the present invention adopted to achieve the intended purpose, the present invention will be described in detail with reference to the accompanying drawings and preferred embodiments.
The method for transferring Native objects among the real Native components can transfer any type of Native objects through javascript. The method of transferring native objects between Reactnative components and the steps thereof of the present invention will be described in detail below.
The fact Native is a technology for constructing Native apps by using javascript and exact, which is introduced by facebook. Note that the native objects according to the present invention are all native objects that cannot be used by javascript in the prior art. In the real Native, the Native objects are generated by a certain real Native component or a real Native interface, and are transmitted to another real Native component or a real Native interface for use through the Javascript, and the Javascript does not use the real Native objects.
First embodiment
As shown in fig. 1 and fig. 2, the method for transferring Native objects between read Native components disclosed in this embodiment includes: step S2: the memory data management module packages a Native object to be boxed of a first read Native component (such as the read Native component A in FIG. 2) into a universal type boxing object; step S4: the first read Native component sends the boxing object to a javascript business logic module; step S5: a second React Native component (such as a reactive Native component B in fig. 2) receives the boxed object forwarded by the javascript service logic module; step S6: and the internal memory data management module carries out unpacking operation on the packed object to obtain a native object.
According to the method and the device, the native object to be boxed is packaged and unpacked through the native end package memory data management module, and the transfer of the native object which cannot be identified by the javascript service logic module is achieved.
The Javascript business logic module is a logic for business development by a front-end developer by using Javascript, depends on the real Native component, and completes the construction of an interface and calls the Native function by using the real Native component and an interface. The Javascript business logic module adds identification bits in the packaged boxing object through the memory data management module to judge whether the obtained boxing object is boxing data or general type data.
Second embodiment
As shown in fig. 2, on the basis of the first embodiment, step S2: after the internal memory data management module encapsulates the Native object to be boxed of the first ReactNative component (e.g., the ReactNative component a in fig. 2) into a universal type of box object, the method for transferring the Native object between the ReactNative components in this embodiment further includes: step S3: and saving the strong reference of the native object to be boxed. The purpose of this embodiment is that, when boxing, the memory data management module retains the strong reference of the native object to be boxed, and prevents the native object from being released.
Further, step S3: after saving the strong reference of the native object to be boxed, the method for transferring the native object between the ReactNative components in the embodiment further includes: step S8: the javascript service logic module sends a release instruction to the memory data management component; and the memory data management component calls a removal reference interface of the memory data management module based on the release instruction to remove the strong reference of the native object to be boxed. The embodiment encapsulates the memory data management component, so that the javascript can directly operate the strong reference of the packaged native object through the memory data management component, the complete life cycle of the native object is ensured, and the memory data management module is prevented from not releasing the native object all the time.
Third embodiment
As shown in fig. 2, on the basis of the first embodiment and the second embodiment, step S2: before the memory data management module packages a Native object to be boxed of a first read Native component (e.g., the read Native component a in fig. 2) into a universal type of box object, the method for transferring the Native object between the read Native components in this embodiment further includes: a first real Native component calls a packing method of a memory data management module; accordingly, step S6: before the memory data management module unpacks the packed object and obtains the Native object, the method for transferring the Native object between the real Native components in the embodiment further includes: the second real Native component (e.g., real Native component B in fig. 2) calls the unpacking method of the memory data management module.
In this embodiment, a memory data management module is established at a Native end and used for managing a Native object to be delivered by a javascript, and a first real Native component calls a boxing method of the memory data management module before the Native object needs to be delivered to the javascript, and packages the Native object into a universal type boxing object. And when the second ReactNative component receives the boxing object, calling an unpacking method of the memory data management module to obtain the original native object to be boxed.
Fourth embodiment
As shown in fig. 2, the present embodiment provides an apparatus for transferring Native objects between read Native components, including: the memory data management module is used for packaging the native object to be boxed of the first Reactnative component into a universal type boxing object; a first real Native component (for example, the real Native component a in fig. 2) for sending the boxed object to the javascript service logic module; a second real Native component (e.g., the real Native component B in fig. 2) configured to receive the boxed object forwarded by the javascript service logic module; and the memory data management module is also used for unpacking the packed object to obtain a native object.
As shown in fig. 3, the memory data management module provides a native interface for packing and unpacking native objects for a native end, the packing interface converts the native objects of special types of the native into general types that can be received by javascript, and the unpacking interface performs reverse operation to restore packed data to native objects to be packed.
Fifth embodiment
As shown in fig. 2, in the device for transferring Native objects between read Native components, the memory data management and storage module is further configured to: and saving the strong reference of the native object to be boxed.
Further, the apparatus for transferring Native objects between read Native components in this embodiment further includes a memory data management component, configured to: under the condition that the javascript service logic module sends a release instruction to the memory data management module, the memory data management module calls a dereferencing interface (see a dereferencing interface in the RN interface of fig. 3) of the memory data management module based on the release instruction to remove strong citation of a native object to be boxed.
The memory data management module maintains a data structure, such as a stack, for storing strong references of native objects which execute the boxing operation, preventing the native objects from being released, and providing a reference removal interface for removing the strong references, wherein the reference removal interface receives the native objects to be boxed or boxed objects to be boxed, and removes the specified native objects to be boxed in the maintained data structure.
The real Native memory data management component is a channel for directly operating the memory data management module by javascript. The assembly at least provides a removal interface for removing the strong reference of the native object to be boxed, and the removal interface is packaged corresponding to the removal reference interface of the memory data management module, so that the memory data management module is informed to release the native object after the javascript finishes using the native object, the native object is prevented from being released, and the complete life cycle of the native object to be boxed is ensured. In addition, other interfaces can be added in the component according to needs, so that the operation of the javascript on the memory data management module is more flexible.
As shown in fig. 3, in the memory data management module, the data storage layer is encapsulated first, and then a data management layer is encapsulated, at least an add interface and a delete interface are provided (other interfaces such as replacement and search can be freely added according to requirements), so as to provide a uniform service for the upper layer. And then, on the basis of a data management layer, encapsulating an interface layer, wherein the interface layer comprises a Native interface and a real Native interface (such as an RN interface in the figure), and respectively encapsulating a Native calling interface and a real Native calling interface. The Native interface provides a boxing method and an unpacking method for the real Native component, and the real Native interface provides strong reference for removing a Native object to be boxed for the javascript.
Sixth embodiment
As shown in fig. 2, the first read Native component (e.g., read Native component a in fig. 2) is further configured to: calling a boxing method of the memory data management module before the memory data management module packages a Native object to be boxed of the first read Native component into a universal type boxing object; accordingly, a second read Native component (e.g., read Native component B in fig. 2) is also used to: and the second real Native component calls an unpacking method of the memory data management module before the memory data management module unpacks the packed object to obtain the Native object.
The first real Native component and the second real Native component are both custom-packaged real Native components, the real Native components depend on the memory data management module, when a special object at a Native end needs to be transmitted to javascript, a boxing method of the memory data management module needs to be called, the boxed object is transmitted to javascript, and when the boxed object is received, a unpacking method of the memory data management module needs to be called to obtain the original Native object to be boxed.
Illustrate by way of example
A packing interface of the memory data management module receives a native object of an id (any) type, the native object is used for appointing a native object to be packed, dictionary type data is returned, packing operation converts the native object of the id type to be packed into a packing object of a dictionary type, and the returned packing object of the dictionary type comprises at least one key: and the address is used for recording the memory address of the native object with the id type.
And after an unpacking interface of the memory data management module receives a dictionary type packing object, unpacking the packing object and returning to the original native object of the id type. And the unpacking operation analyzes the packing object of the dictionary type, and converts the memory address pointed by the address into a native object of the id type.
And adding a dictionary type data structure called a packing object life cycle management dictionary in the memory data management module, and initializing the data structure when the memory data management module is initialized. Each time a bin packing operation is performed, the key in the bin packed object is used: and inserting a piece of data into the packing object life cycle management dictionary by taking the value corresponding to the address as a key and the native object of the id type of the packing operation as a value. In addition, after the removal reference interface receives a Native object of an id type, the value of the second real Native component is returned to be null. The removal reference interface firstly judges whether the received native object is of a dictionary type, if the native object is of the dictionary type, the native object is regarded as a boxed object, the value of the address field is read, and data taking the value as key is removed from a boxed object life cycle management dictionary; if the received native object is not of the dictionary type, the native object is considered as the native object to be boxed before boxing, the object memory address pointed by the native object to be boxed is converted into a character string, and data taking the character string as a key is removed from the lifecycle management dictionary of the boxing object.
While the invention has been described in connection with specific embodiments thereof, it is to be understood that it is intended by the appended drawings and description that the invention may be embodied in other specific forms without departing from the spirit or scope of the invention.
Claims (8)
1. A method of transferring native objects between ReactNative components, comprising:
the memory data management module packages a Native object to be boxed of the first read Native component into a universal type boxing object;
the first ReactNative component sends the boxed object to a javascript business logic module;
the second ReactNative component receives the boxing object forwarded by the javascript service logic module;
and the internal memory data management module carries out unpacking operation on the boxed object to obtain the native object.
2. The method of claim 1, wherein after the memory data management module packages native objects of the first Reactnative component to be boxed into a boxed object of a generic type, the method further comprises:
and saving the strong reference of the native object to be boxed.
3. The method according to claim 2, wherein after saving the strong reference of the native object to be boxed, the method further comprises:
the javascript service logic module sends a release instruction to the memory data management component;
and the memory data management component calls a removal reference interface of the memory data management module based on the release instruction to remove the strong reference of the native object to be boxed.
4. The method of any of claims 1 to 3, wherein before the memory data management module packages native objects of the first Reactnative component to be boxed into a boxed object of a generic type, the method further comprises:
the first Reactnative component calls a boxing method of the memory data management module, and the boxing method is used for packaging the native object into a universal type boxing object;
correspondingly, before the memory data management module unpacks the packed object and obtains the native object, the method further includes:
and the second ReactNative component calls an unpacking method of the memory data management module.
5. An apparatus for transferring native objects between Reactnative components, comprising:
the memory data management module is used for packaging the native object to be boxed of the first Reactnative component into a universal type boxing object;
the first ReactNative component is used for sending the boxed object to a javascript business logic module;
the second ReactNative component is used for receiving the boxing object forwarded by the javascript service logic module;
the memory data management module is further configured to perform unpacking operation on the packed object to obtain the native object.
6. The apparatus of claim 5, wherein the memory data management module is further configured to:
and saving the strong reference of the native object to be boxed.
7. The apparatus of claim 6, further comprising a memory data management component configured to:
and under the condition that the javascript business logic module sends a release instruction to the memory data management module, the memory data management module calls a removal reference interface of the memory data management module based on the release instruction to remove the strong reference of the native object to be boxed.
8. The apparatus of claim 6 or 7, wherein the first React Native component is further configured to:
before the native object to be boxed of the first Reactnative component is packaged into a boxed object of a general type by the internal memory data management module, calling a boxing method of the internal memory data management module, wherein the boxing method is used for packaging the native object into a boxed object of a general type;
accordingly, the second ReactNative component is further configured to:
and the second real Native component calls an unpacking method of the memory data management module before the unpacked object is obtained after the unpacked object is subjected to unpacking operation by the memory data management module.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611234768.0A CN106843850B (en) | 2016-12-28 | 2016-12-28 | Method and device for transferring Native objects between read Native components |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201611234768.0A CN106843850B (en) | 2016-12-28 | 2016-12-28 | Method and device for transferring Native objects between read Native components |
Publications (2)
Publication Number | Publication Date |
---|---|
CN106843850A CN106843850A (en) | 2017-06-13 |
CN106843850B true CN106843850B (en) | 2020-05-15 |
Family
ID=59114343
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201611234768.0A Active CN106843850B (en) | 2016-12-28 | 2016-12-28 | Method and device for transferring Native objects between read Native components |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN106843850B (en) |
Families Citing this family (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107908398A (en) * | 2017-11-08 | 2018-04-13 | 四川长虹电器股份有限公司 | Method based on React technique constructions web applications |
CN108804197B (en) * | 2018-06-19 | 2022-04-05 | 北京五八信息技术有限公司 | Dynamic componentization implementation method, device, equipment and storage medium |
CN109032583B (en) * | 2018-07-25 | 2022-06-17 | 北京小米移动软件有限公司 | Data interaction method and device |
CN108958943B (en) * | 2018-07-25 | 2021-02-09 | 北京小米移动软件有限公司 | Memory release method and device |
Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105468369A (en) * | 2015-11-19 | 2016-04-06 | 深圳联友科技有限公司 | Method and system for calling native function by JavaScript on mobile platform |
CN105589693A (en) * | 2015-12-18 | 2016-05-18 | 国云科技股份有限公司 | React-native-based method for rapidly realizing data acquisition of mobile terminals |
-
2016
- 2016-12-28 CN CN201611234768.0A patent/CN106843850B/en active Active
Patent Citations (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN105468369A (en) * | 2015-11-19 | 2016-04-06 | 深圳联友科技有限公司 | Method and system for calling native function by JavaScript on mobile platform |
CN105589693A (en) * | 2015-12-18 | 2016-05-18 | 国云科技股份有限公司 | React-native-based method for rapidly realizing data acquisition of mobile terminals |
Non-Patent Citations (2)
Title |
---|
8) React Native 与原生之间的通信(iOS);朱_源浩;《https://www.jianshu.com/p/9d7dbf17daa5》;20160826;1-22 * |
React Native 的组件通信方式;Alon Zhang;《https://jinlong.github.io/2016/12/16/react-native-component-communication/》;20161216;1-5 * |
Also Published As
Publication number | Publication date |
---|---|
CN106843850A (en) | 2017-06-13 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN106843850B (en) | Method and device for transferring Native objects between read Native components | |
US9183032B2 (en) | Method and system for migration of multi-tier virtual application across different clouds hypervisor platforms | |
CN106022483B (en) | The method and apparatus converted between machine learning model | |
CN106415506B (en) | For calling the group scheme of the object-oriented of safety zone | |
CN111158690B (en) | Desktop application framework, construction method, desktop application running method and storage medium | |
CN108563517A (en) | The call method and device of system interface | |
CN107122252B (en) | Intersystem interaction method and device | |
CN102622211A (en) | Method for application development and device | |
CN105677302A (en) | Application program modularization developing method and device | |
CN109933350B (en) | Method and device for embedding codes in application and electronic equipment | |
CN105162673A (en) | Data transmission interface and method | |
CN102708076B (en) | Driver calking | |
CN107977260B (en) | Task submitting method and device | |
CN103150161B (en) | Based on task encapsulation method and the device of MapReduce computation module | |
CN111324395B (en) | Calling method, device and computer readable storage medium | |
EP3797356A1 (en) | Code base sharing between standalone and web-based versions of an application via an emulated network communication channel | |
CN105335174B (en) | A kind of java application of non-OSGi calls the method and device of OSGi service | |
CN111736844B (en) | Database cloud service standard interface and implementation method | |
CN106484375B (en) | Instruction block loading method, soft switch equipment and system | |
WO2017076244A1 (en) | Method, device and related system for dynamically repairing application | |
CN116954831A (en) | Method and system for generating container mirror image package based on assembly file | |
US9400663B2 (en) | Managing middleware using an application manager | |
CN112506871B (en) | Automated task management and log management method, system, electronic device and medium | |
CN109284112B (en) | Method and device for running application program | |
CN106201593A (en) | A kind of startup method and device of application program |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |