├── .circleci
└── config.yml
├── .gitattributes
├── .gitignore
├── .npmignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── RNTreasureData.podspec
├── android
├── build.gradle
├── gradle
│ └── wrapper
│ │ ├── gradle-wrapper.jar
│ │ └── gradle-wrapper.properties
├── gradlew
├── gradlew.bat
└── src
│ └── main
│ ├── AndroidManifest.xml
│ └── java
│ └── com
│ └── github
│ └── quipper
│ └── rn
│ └── td
│ ├── RNTreasureDataModule.java
│ ├── RNTreasureDataPackage.java
│ └── Utils.java
├── example
├── .babelrc
├── .gitattributes
├── .gitignore
├── .watchmanconfig
├── android
│ ├── app
│ │ ├── BUCK
│ │ ├── build.gradle
│ │ ├── proguard-rules.pro
│ │ └── src
│ │ │ └── main
│ │ │ ├── AndroidManifest.xml
│ │ │ ├── assets
│ │ │ └── .gitkeep
│ │ │ ├── java
│ │ │ └── com
│ │ │ │ └── rntreasuredataexample
│ │ │ │ ├── MainActivity.java
│ │ │ │ └── MainApplication.java
│ │ │ └── res
│ │ │ ├── mipmap-hdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-mdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xhdpi
│ │ │ └── ic_launcher.png
│ │ │ ├── mipmap-xxhdpi
│ │ │ └── ic_launcher.png
│ │ │ └── values
│ │ │ ├── strings.xml
│ │ │ └── styles.xml
│ ├── build.gradle
│ ├── gradle.properties
│ ├── gradle
│ │ └── wrapper
│ │ │ ├── gradle-wrapper.jar
│ │ │ └── gradle-wrapper.properties
│ ├── gradlew
│ ├── gradlew.bat
│ ├── keystores
│ │ ├── BUCK
│ │ └── debug.keystore.properties
│ └── settings.gradle
├── app.json
├── index.js
├── ios
│ ├── Podfile
│ ├── Podfile.lock
│ ├── RNTreasureDataExample-tvOS
│ │ └── Info.plist
│ ├── RNTreasureDataExample-tvOSTests
│ │ └── Info.plist
│ ├── RNTreasureDataExample.xcodeproj
│ │ ├── project.pbxproj
│ │ └── xcshareddata
│ │ │ └── xcschemes
│ │ │ ├── RNTreasureDataExample-tvOS.xcscheme
│ │ │ └── RNTreasureDataExample.xcscheme
│ ├── RNTreasureDataExample.xcworkspace
│ │ └── contents.xcworkspacedata
│ ├── RNTreasureDataExample
│ │ ├── AppDelegate.h
│ │ ├── AppDelegate.m
│ │ ├── Base.lproj
│ │ │ └── LaunchScreen.xib
│ │ ├── Images.xcassets
│ │ │ ├── AppIcon.appiconset
│ │ │ │ └── Contents.json
│ │ │ └── Contents.json
│ │ ├── Info.plist
│ │ └── main.m
│ └── RNTreasureDataExampleTests
│ │ ├── Info.plist
│ │ └── RNTreasureDataExampleTests.m
├── package.json
├── src
│ └── App.tsx
├── tsconfig.json
└── yarn.lock
├── ios
├── RNTreasureData.h
├── RNTreasureData.m
└── RNTreasureData.xcodeproj
│ └── project.pbxproj
├── package.json
├── src
├── declarations.d.ts
└── index.ts
├── tsconfig.json
├── tslint.json
└── yarn.lock
/.circleci/config.yml:
--------------------------------------------------------------------------------
1 | version: 2
2 | jobs:
3 | bundle_dependencies:
4 | working_directory: ~/react-native-td
5 | docker:
6 | - image: circleci/node:8.7.0
7 | steps:
8 | - checkout
9 | - restore_cache:
10 | keys:
11 | - react-native-td-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
12 | - react-native-td-{{ arch }}
13 | - run:
14 | name: System information
15 | command: |
16 | echo "Node $(node -v)"
17 | echo "npm $(node -v)"
18 | - run:
19 | name: Install dependencies
20 | command: 'npm install'
21 | - save_cache:
22 | key: react-native-td-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
23 | paths:
24 | - ~/react-native-td/node_modules
25 | - ~/.cache/yarn
26 |
27 | compile_source:
28 | working_directory: ~/react-native-td
29 | docker:
30 | - image: circleci/node:8.7.0
31 | steps:
32 | - checkout
33 | - restore_cache:
34 | keys:
35 | - react-native-td-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
36 | - react-native-td-{{ arch }}
37 | - run:
38 | name: Install dependencies
39 | command: 'npm install'
40 | - run:
41 | name: Compile TypeScript
42 | command: 'npm run tsc'
43 | - run:
44 | name: Compile example module
45 | command: |
46 | cd ./example
47 | npm install
48 | npm run tsc
49 | npm run build:ios
50 | npm run build:android
51 |
52 | deploy_to_npm:
53 | working_directory: ~/react-native-td
54 | docker:
55 | - image: circleci/node:8.7.0
56 | steps:
57 | - checkout
58 | - restore_cache:
59 | keys:
60 | - react-native-td-{{ arch }}-{{ .Branch }}-{{ checksum "yarn.lock" }}
61 | - react-native-td-{{ arch }}
62 | - run:
63 | name: Install dependencies
64 | command: 'npm install'
65 | - run:
66 | name: Compile TypeScript
67 | command: 'npm run tsc'
68 | - run:
69 | name: Login to npm and publish
70 | command: |
71 | echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> ~/.npmrc
72 | npm publish
73 |
74 | workflows:
75 | version: 2
76 | build_and_deploy:
77 | jobs:
78 | - bundle_dependencies:
79 | filters:
80 | tags:
81 | only: /.*/
82 | branches:
83 | only: /.*/
84 | - compile_source:
85 | requires:
86 | - bundle_dependencies
87 | filters:
88 | tags:
89 | only: /.*/
90 | branches:
91 | only: /.*/
92 | - deploy_to_npm:
93 | requires:
94 | - compile_source
95 | filters:
96 | tags:
97 | only: /.*/
98 | branches:
99 | ignore: /.*/
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | *.pbxproj -text
2 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # OSX
2 | #
3 | .DS_Store
4 |
5 | # node.js
6 | #
7 | node_modules/
8 | npm-debug.log
9 | yarn-error.log
10 |
11 | # Xcode
12 | #
13 | build/
14 | *.pbxuser
15 | !default.pbxuser
16 | *.mode1v3
17 | !default.mode1v3
18 | *.mode2v3
19 | !default.mode2v3
20 | *.perspectivev3
21 | !default.perspectivev3
22 | xcuserdata
23 | *.xccheckout
24 | *.moved-aside
25 | DerivedData
26 | *.hmap
27 | *.ipa
28 | *.xcuserstate
29 | project.xcworkspace
30 | */ios/Pods
31 | *.jsbundle
32 | *.jsbundle.meta
33 |
34 | # Android/IntelliJ
35 | #
36 | build/
37 | .idea
38 | .gradle
39 | .settings
40 | local.properties
41 | *.iml
42 | *.classpath
43 | *.project
44 | *.android.bundle
45 | *.android.bundle.meta
46 |
47 | # BUCK
48 | buck-out/
49 | \.buckd/
50 | *.keystore
51 |
--------------------------------------------------------------------------------
/.npmignore:
--------------------------------------------------------------------------------
1 | *.DS_Store
2 |
3 | # Xcode
4 | *.pbxuser
5 | *.mode1v3
6 | *.mode2v3
7 | *.perspectivev3
8 | *.xcuserstate
9 | project.xcworkspace/
10 | xcuserdata/
11 |
12 | # Android
13 | android/local.properties
14 | android/.gradle/
15 | android/.idea/
16 | android/gradlew
17 | android/build
18 | android/gradlew.bat
19 | android/gradle/
20 |
21 | # Config files
22 | .babelrc
23 | tsconfig.json
24 | tslint.json
25 | yarn.lock
26 |
27 | # Others
28 | example/
29 | build
30 | node_modules
31 | src/
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | - 0.9.3 2018/07/01
2 | - [Fix][Add React dependency to podspec](https://github.com/quipper/react-native-td/pull/17)
3 | - [Fix][isFirstRun was calling callback method twice](https://github.com/quipper/react-native-td/pull/18)
4 | - 0.9.2 2018/03/17
5 | - [Fix][Fix typo](https://github.com/quipper/react-native-td/pull/14)
6 | - 0.9.1 2018/01/09
7 | - 1st release
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-native-td [](https://circleci.com/gh/quipper/react-native-td) [](https://badge.fury.io/js/react-native-td)
2 |
3 | react-native-td is an unofficial React Native SDK for Treasure Data.
4 |
5 | The module is a light-weight layer sitting on-top of the TreasureData SDK for both [iOS](https://github.com/treasure-data/td-ios-sdk) and [Android](https://github.com/treasure-data/td-android-sdk).
6 |
7 | ## Installation
8 |
9 | You can install react-native-td into your project in the following way.
10 |
11 | ```sh
12 | npm install --save react-native-td
13 | react-native link react-native-td
14 | ```
15 |
16 | ### iOS configuration
17 |
18 | If you haven't introduced cocoapods, install it and run `pod init` under `ios/`and make sure lines below are in `Podfile`.
19 |
20 | ```diff
21 | + pod 'React', :path => '../node_modules/react-native', :subspecs => [
22 | + 'Core',
23 | + 'DevSupport', # Include this to enable In-App Devmenu if RN >= 0.43
24 | + 'RCTText',
25 | + 'RCTNetwork',
26 | + 'RCTWebSocket', # needed for debugging
27 | + ]
28 | + pod 'yoga', :path => '../node_modules/react-native/ReactCommon/yoga'
29 | + pod 'RNTreasureData', :path => '../node_modules/react-native-td'
30 | ```
31 |
32 | ## Usage
33 |
34 | Basically react-native-td imitates the interface of TreasureData iOS/Android SDK as close as possible.
35 |
36 | Hence to know more detail check official documents below.
37 |
38 | - iOS: https://docs.treasuredata.com/articles/ios-sdk
39 | - Android: https://docs.treasuredata.com/articles/android-sdk
40 |
41 | ### Instantiate with your API key
42 |
43 | ```ts
44 | import TreasureData from "react-native-td";
45 |
46 | TreasureData.initialize("your API key");
47 | ```
48 |
49 | We recommend to use a write-only API key for the SDK. To obtain one, please:
50 |
51 | 1. Login to the Treasure Data Console at http://console.treasuredata.com;
52 | 2. Visit your Profile page at http://console.treasuredata.com/users/current;
53 | 3. Insert your password under the 'API Keys' panel;
54 | 4. In the bottom part of the panel, under 'Write-Only API keys', either copy the API key or click on 'Generate New' and copy the new API key.
55 |
56 | ### Add a event to local buffer
57 |
58 | To add an event to local buffer, you can call `addEvent` or `addEventWithCallback` API.
59 |
60 | ```ts
61 | TreasureData.addEventWithCallback(
62 | { event: "event_name" },
63 | "database_name",
64 | "record_name",
65 | () => {
66 | console.log("onSuccess is called.");
67 | },
68 | (error, message) => {
69 | console.log(`Error: ${error}`);
70 | console.log(`Message: ${message}`);
71 | }
72 | );
73 | ```
74 |
75 | Or simply:
76 |
77 | ```ts
78 | TreasureData.addEvent("database_name", "table_name", { event: "event_name" });
79 | ```
80 |
81 | ### Upload buffered events to Treasure Data
82 |
83 | To upload events buffered events to Treasure Data, you can call `uploadEvents` or `uploadEventsWithCallback` API.
84 |
85 | ```ts
86 | TreasureData.uploadEventsWithCallback(
87 | () => {
88 | console.log("onSuccess is called.");
89 | },
90 | (error, message) => {
91 | console.log(`Error: ${error}`);
92 | console.log(`Message: ${message}`);
93 | }
94 | );
95 | ```
96 |
97 | Or simply:
98 |
99 | ```ts
100 | TreasureData.uploadEvents();
101 | ```
102 |
103 | ### Start/End session
104 |
105 | ```ts
106 | TreasureData.startSession("table_name");
107 |
108 | TreasureData.endSession("table_name");
109 | ```
110 |
111 | If you want to handle the following case, use a pair of methods `startSession` and `endSession` for global session tracking.
112 |
113 | * User opens the application and starts session tracking using startSession
114 | * User moves to home screen and finishes the session using endSession
115 | * User reopens the application and restarts session tracking within default 10 seconds. But you want to deal with this new session as the same session.
116 |
117 | ```ts
118 | TreasureData.setSessionTimeoutMilli(30 * 1000); // Default is 10 seconds
119 |
120 | TreasureData.startSession();
121 |
122 | TreasureData.endSession();
123 | ```
124 |
125 | In this case, you can get the current session ID using `getSessionId`.
126 |
127 | ```ts
128 | TreasureData.getSessionId().then(sessionId => {
129 | console.log(sessionId);
130 | });
131 | ```
132 |
133 | ### Detect if it's the first running
134 |
135 | You can detect if it's the first running or not easily using `isFirstRun` method and then clear the flag with `clearFirstRun`.
136 |
137 | ```ts
138 | TreasureData.isFirstRun()
139 | .then(() => {
140 | TreasureData.clearFirstRun();
141 | TreasureData.uploadEvents();
142 | })
143 | .catch(error => {
144 | console.log(error);
145 | });
146 | ```
147 |
148 | ## About Error code
149 |
150 | `addEventWithCallback` and `uploadEventsWithCallback` methods call back `onError` with errorCode argument.
151 |
152 | This argument is useful to know the cause type of the error. There are the following error codes.
153 |
154 | * `init_error` : The initialization failed.
155 | * `invalid_param` : The parameter passed to the API was invalid
156 | * `invalid_event` : The event was invalid
157 | * `data_conversion` : Failed to convert the data to/from JSON
158 | * `storage_error` : Failed to read/write data in the storage
159 | * `network_error` : Failed to communicate with the server due to network problem
160 | * `server_response` : The server returned an error response
161 |
162 | ## Additional Configuration
163 |
164 | ### Endpoint
165 |
166 | ```ts
167 | TreasureData.initializeApiEndpoint("https://in.treasuredata.com");
168 | TreasureData.initialize("your API key");
169 | ```
170 |
171 | ### Encryption key
172 |
173 | ```ts
174 | TreasureData.initializeEncryptionKey("hello world");
175 | ```
176 |
177 | ### Default database
178 |
179 | ```ts
180 | TreasureData.setDefaultDatabase("default_db");
181 | ```
182 |
183 | ### Adding UUID of the device to each event automatically
184 |
185 | ```ts
186 | TreasureData.enableAutoAppendUniqId();
187 | ```
188 |
189 | ### Adding an UUID to each event record automatically
190 |
191 | ```ts
192 | TreasureData.enableAutoAppendRecordUUID();
193 | ```
194 |
195 | ### Adding device model information to each event automatically
196 |
197 | ```ts
198 | TreasureData.enableAutoAppendModelInformation();
199 | ```
200 |
201 | ### Adding application package version information to each event automatically
202 |
203 | ```ts
204 | TreasureData.enableAutoAppendAppInformation();
205 | ```
206 |
207 | ### Adding locale configuration information to each event automatically
208 |
209 | ```ts
210 | TreasureData.enableAutoAppendLocaleInformation();
211 | ```
212 |
213 | ### Use server side upload timestamp
214 |
215 | ```ts
216 | TreasureData.enableServerSideUploadTimestamp();
217 | // Add server side upload time as a customized column name
218 | TreasureData.enableServerSideUploadTimestamp("server_upload_time");
219 | ```
220 |
221 | ### Enable/Disable debug log
222 |
223 | ```ts
224 | TreasureData.enableLogging();
225 | TreasureData.disableLogging();
226 | ```
227 |
--------------------------------------------------------------------------------
/RNTreasureData.podspec:
--------------------------------------------------------------------------------
1 | require 'json'
2 | package = JSON.parse(File.read('./package.json'))
3 |
4 | Pod::Spec.new do |s|
5 | s.name = "RNTreasureData"
6 | s.version = package["version"]
7 | s.summary = package["description"]
8 | s.description = <<-DESC
9 | An unofficial React Native SDK for Treasure Data.
10 | The module is a light-weight layer sitting on-top of the TreasureData SDK for both iOS and Android.
11 | DESC
12 | s.homepage = "https://github.com/quipper/react-native-td"
13 | s.license = package['license']
14 | s.author = package['author']
15 | s.platform = :ios, "7.0"
16 | s.source = { :git => 'https://github.com/quipper/react-native-td.git' }
17 | s.source_files = "ios/*.{h,m}"
18 | s.requires_arc = true
19 |
20 | s.dependency "TreasureData-iOS-SDK"
21 | s.dependency "React"
22 | end
23 |
--------------------------------------------------------------------------------
/android/build.gradle:
--------------------------------------------------------------------------------
1 |
2 | buildscript {
3 | repositories {
4 | jcenter()
5 | }
6 |
7 | dependencies {
8 | classpath 'com.android.tools.build:gradle:2.3.3'
9 | }
10 | }
11 |
12 | apply plugin: 'com.android.library'
13 |
14 | android {
15 | compileSdkVersion 26
16 | buildToolsVersion '25.0.3'
17 |
18 | defaultConfig {
19 | minSdkVersion 16
20 | targetSdkVersion 26
21 | versionCode 1
22 | versionName "1.0"
23 | }
24 | lintOptions {
25 | abortOnError false
26 | }
27 | }
28 |
29 | repositories {
30 | mavenCentral()
31 | }
32 |
33 | dependencies {
34 | compile 'com.facebook.react:react-native:+'
35 | compile 'com.treasuredata:td-android-sdk:0.1.16'
36 | }
37 |
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.jar:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/quipper/react-native-td/84a1e05e978cc7c481335b5d16e0a3ffae304684/android/gradle/wrapper/gradle-wrapper.jar
--------------------------------------------------------------------------------
/android/gradle/wrapper/gradle-wrapper.properties:
--------------------------------------------------------------------------------
1 | #Sat Jan 06 13:56:14 JST 2018
2 | distributionBase=GRADLE_USER_HOME
3 | distributionPath=wrapper/dists
4 | zipStoreBase=GRADLE_USER_HOME
5 | zipStorePath=wrapper/dists
6 | distributionUrl=https\://services.gradle.org/distributions/gradle-4.1-all.zip
7 |
--------------------------------------------------------------------------------
/android/gradlew:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env bash
2 |
3 | ##############################################################################
4 | ##
5 | ## Gradle start up script for UN*X
6 | ##
7 | ##############################################################################
8 |
9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
10 | DEFAULT_JVM_OPTS=""
11 |
12 | APP_NAME="Gradle"
13 | APP_BASE_NAME=`basename "$0"`
14 |
15 | # Use the maximum available, or set MAX_FD != -1 to use that value.
16 | MAX_FD="maximum"
17 |
18 | warn ( ) {
19 | echo "$*"
20 | }
21 |
22 | die ( ) {
23 | echo
24 | echo "$*"
25 | echo
26 | exit 1
27 | }
28 |
29 | # OS specific support (must be 'true' or 'false').
30 | cygwin=false
31 | msys=false
32 | darwin=false
33 | case "`uname`" in
34 | CYGWIN* )
35 | cygwin=true
36 | ;;
37 | Darwin* )
38 | darwin=true
39 | ;;
40 | MINGW* )
41 | msys=true
42 | ;;
43 | esac
44 |
45 | # Attempt to set APP_HOME
46 | # Resolve links: $0 may be a link
47 | PRG="$0"
48 | # Need this for relative symlinks.
49 | while [ -h "$PRG" ] ; do
50 | ls=`ls -ld "$PRG"`
51 | link=`expr "$ls" : '.*-> \(.*\)$'`
52 | if expr "$link" : '/.*' > /dev/null; then
53 | PRG="$link"
54 | else
55 | PRG=`dirname "$PRG"`"/$link"
56 | fi
57 | done
58 | SAVED="`pwd`"
59 | cd "`dirname \"$PRG\"`/" >/dev/null
60 | APP_HOME="`pwd -P`"
61 | cd "$SAVED" >/dev/null
62 |
63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
64 |
65 | # Determine the Java command to use to start the JVM.
66 | if [ -n "$JAVA_HOME" ] ; then
67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
68 | # IBM's JDK on AIX uses strange locations for the executables
69 | JAVACMD="$JAVA_HOME/jre/sh/java"
70 | else
71 | JAVACMD="$JAVA_HOME/bin/java"
72 | fi
73 | if [ ! -x "$JAVACMD" ] ; then
74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
75 |
76 | Please set the JAVA_HOME variable in your environment to match the
77 | location of your Java installation."
78 | fi
79 | else
80 | JAVACMD="java"
81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
82 |
83 | Please set the JAVA_HOME variable in your environment to match the
84 | location of your Java installation."
85 | fi
86 |
87 | # Increase the maximum file descriptors if we can.
88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then
89 | MAX_FD_LIMIT=`ulimit -H -n`
90 | if [ $? -eq 0 ] ; then
91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
92 | MAX_FD="$MAX_FD_LIMIT"
93 | fi
94 | ulimit -n $MAX_FD
95 | if [ $? -ne 0 ] ; then
96 | warn "Could not set maximum file descriptor limit: $MAX_FD"
97 | fi
98 | else
99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
100 | fi
101 | fi
102 |
103 | # For Darwin, add options to specify how the application appears in the dock
104 | if $darwin; then
105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
106 | fi
107 |
108 | # For Cygwin, switch paths to Windows format before running java
109 | if $cygwin ; then
110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"`
111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
112 | JAVACMD=`cygpath --unix "$JAVACMD"`
113 |
114 | # We build the pattern for arguments to be converted via cygpath
115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
116 | SEP=""
117 | for dir in $ROOTDIRSRAW ; do
118 | ROOTDIRS="$ROOTDIRS$SEP$dir"
119 | SEP="|"
120 | done
121 | OURCYGPATTERN="(^($ROOTDIRS))"
122 | # Add a user-defined pattern to the cygpath arguments
123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then
124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
125 | fi
126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh
127 | i=0
128 | for arg in "$@" ; do
129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
131 |
132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
134 | else
135 | eval `echo args$i`="\"$arg\""
136 | fi
137 | i=$((i+1))
138 | done
139 | case $i in
140 | (0) set -- ;;
141 | (1) set -- "$args0" ;;
142 | (2) set -- "$args0" "$args1" ;;
143 | (3) set -- "$args0" "$args1" "$args2" ;;
144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;;
145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
150 | esac
151 | fi
152 |
153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules
154 | function splitJvmOpts() {
155 | JVM_OPTS=("$@")
156 | }
157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS
158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME"
159 |
160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@"
161 |
--------------------------------------------------------------------------------
/android/gradlew.bat:
--------------------------------------------------------------------------------
1 | @if "%DEBUG%" == "" @echo off
2 | @rem ##########################################################################
3 | @rem
4 | @rem Gradle startup script for Windows
5 | @rem
6 | @rem ##########################################################################
7 |
8 | @rem Set local scope for the variables with windows NT shell
9 | if "%OS%"=="Windows_NT" setlocal
10 |
11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
12 | set DEFAULT_JVM_OPTS=
13 |
14 | set DIRNAME=%~dp0
15 | if "%DIRNAME%" == "" set DIRNAME=.
16 | set APP_BASE_NAME=%~n0
17 | set APP_HOME=%DIRNAME%
18 |
19 | @rem Find java.exe
20 | if defined JAVA_HOME goto findJavaFromJavaHome
21 |
22 | set JAVA_EXE=java.exe
23 | %JAVA_EXE% -version >NUL 2>&1
24 | if "%ERRORLEVEL%" == "0" goto init
25 |
26 | echo.
27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
28 | echo.
29 | echo Please set the JAVA_HOME variable in your environment to match the
30 | echo location of your Java installation.
31 |
32 | goto fail
33 |
34 | :findJavaFromJavaHome
35 | set JAVA_HOME=%JAVA_HOME:"=%
36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe
37 |
38 | if exist "%JAVA_EXE%" goto init
39 |
40 | echo.
41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
42 | echo.
43 | echo Please set the JAVA_HOME variable in your environment to match the
44 | echo location of your Java installation.
45 |
46 | goto fail
47 |
48 | :init
49 | @rem Get command-line arguments, handling Windowz variants
50 |
51 | if not "%OS%" == "Windows_NT" goto win9xME_args
52 | if "%@eval[2+2]" == "4" goto 4NT_args
53 |
54 | :win9xME_args
55 | @rem Slurp the command line arguments.
56 | set CMD_LINE_ARGS=
57 | set _SKIP=2
58 |
59 | :win9xME_args_slurp
60 | if "x%~1" == "x" goto execute
61 |
62 | set CMD_LINE_ARGS=%*
63 | goto execute
64 |
65 | :4NT_args
66 | @rem Get arguments from the 4NT Shell from JP Software
67 | set CMD_LINE_ARGS=%$
68 |
69 | :execute
70 | @rem Setup the command line
71 |
72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
73 |
74 | @rem Execute Gradle
75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%
76 |
77 | :end
78 | @rem End local scope for the variables with windows NT shell
79 | if "%ERRORLEVEL%"=="0" goto mainEnd
80 |
81 | :fail
82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
83 | rem the _cmd.exe /c_ return code!
84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1
85 | exit /b 1
86 |
87 | :mainEnd
88 | if "%OS%"=="Windows_NT" endlocal
89 |
90 | :omega
91 |
--------------------------------------------------------------------------------
/android/src/main/AndroidManifest.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
--------------------------------------------------------------------------------
/android/src/main/java/com/github/quipper/rn/td/RNTreasureDataModule.java:
--------------------------------------------------------------------------------
1 | package com.github.quipper.rn.td;
2 |
3 | import com.facebook.react.bridge.Callback;
4 | import com.facebook.react.bridge.Promise;
5 | import com.facebook.react.bridge.ReactApplicationContext;
6 | import com.facebook.react.bridge.ReactContextBaseJavaModule;
7 | import com.facebook.react.bridge.ReactMethod;
8 | import com.facebook.react.bridge.ReadableMap;
9 | import com.treasuredata.android.TDCallback;
10 | import com.treasuredata.android.TreasureData;
11 |
12 | import java.util.Map;
13 |
14 | import javax.annotation.Nonnull;
15 | import javax.annotation.Nullable;
16 |
17 | import static com.github.quipper.rn.td.Utils.toHashMap;
18 |
19 | public final class RNTreasureDataModule extends ReactContextBaseJavaModule {
20 |
21 | RNTreasureDataModule(ReactApplicationContext reactContext) {
22 | super(reactContext);
23 | }
24 |
25 | @Override
26 | public String getName() {
27 | return "RNTreasureData";
28 | }
29 |
30 | @Nullable
31 | @Override
32 | public Map getConstants() {
33 | return null;
34 | }
35 |
36 | @ReactMethod
37 | public void initialize(@Nonnull String apiKey) {
38 | TreasureData.initializeSharedInstance(getReactApplicationContext(), apiKey);
39 | }
40 |
41 | @ReactMethod
42 | public void initializeApiEndpoint(@Nonnull String apiEndpoint) {
43 | TreasureData.initializeApiEndpoint(apiEndpoint);
44 | }
45 |
46 | @ReactMethod
47 | public void initializeEncryptionKey(@Nonnull String encryptionKey) {
48 | TreasureData.initializeEncryptionKey(encryptionKey);
49 | }
50 |
51 | @ReactMethod
52 | public void setDefaultDatabase(@Nonnull String databse) {
53 | TreasureData.sharedInstance().setDefaultDatabase(databse);
54 | }
55 |
56 | @ReactMethod
57 | public void enableAutoAppendUniqId() {
58 | TreasureData.sharedInstance().enableAutoAppendUniqId();
59 | }
60 |
61 | @ReactMethod
62 | public void disableAutoAppendUniqId() {
63 | TreasureData.sharedInstance().disableAutoAppendUniqId();
64 | }
65 |
66 | @ReactMethod
67 | public void enableAutoAppendRecordUUID() {
68 | TreasureData.sharedInstance().enableAutoAppendRecordUUID();
69 | }
70 |
71 | @ReactMethod
72 | public void enableAutoAppendRecordUUID(String column) {
73 | TreasureData.sharedInstance().enableAutoAppendRecordUUID(column);
74 | }
75 |
76 | @ReactMethod
77 | public void disableAutoAppendRecordUUID() {
78 | TreasureData.sharedInstance().disableAutoAppendRecordUUID();
79 | }
80 |
81 | @ReactMethod
82 | public void enableAutoAppendModelInformation() {
83 | TreasureData.sharedInstance().enableAutoAppendModelInformation();
84 | }
85 |
86 | @ReactMethod
87 | public void disableAutoAppendModelInformation() {
88 | TreasureData.sharedInstance().disableAutoAppendModelInformation();
89 | }
90 |
91 | @ReactMethod
92 | public void enableAutoAppendAppInformation() {
93 | TreasureData.sharedInstance().enableAutoAppendAppInformation();
94 | }
95 |
96 | @ReactMethod
97 | public void disableAutoAppendAppInformation() {
98 | TreasureData.sharedInstance().disableAutoAppendAppInformation();
99 | }
100 |
101 | @ReactMethod
102 | public void enableAutoAppendLocaleInformation() {
103 | TreasureData.sharedInstance().enableAutoAppendLocaleInformation();
104 | }
105 |
106 | @ReactMethod
107 | public void disableAutoAppendLocaleInformation() {
108 | TreasureData.sharedInstance().disableAutoAppendLocaleInformation();
109 | }
110 |
111 | @ReactMethod
112 | public void enableServerSideUploadTimestamp() {
113 | TreasureData.sharedInstance().enableServerSideUploadTimestamp();
114 | }
115 |
116 | @ReactMethod
117 | public void enableServerSideUploadTimestamp(String column) {
118 | TreasureData.sharedInstance().enableServerSideUploadTimestamp(column);
119 | }
120 |
121 | @ReactMethod
122 | public void disableServerSideUploadTimestamp() {
123 | TreasureData.sharedInstance().disableServerSideUploadTimestamp();
124 | }
125 |
126 | @ReactMethod
127 | public void enableLogging() {
128 | TreasureData.enableLogging();
129 | }
130 |
131 | @ReactMethod
132 | public void disableLogging() {
133 | TreasureData.disableLogging();
134 | }
135 |
136 | @ReactMethod
137 | public void addEvent(ReadableMap record, String database, String table) {
138 | TreasureData.sharedInstance().addEvent(database, table, toHashMap(record));
139 | }
140 |
141 | @ReactMethod
142 | public void addEvent(ReadableMap record, String table) {
143 | TreasureData.sharedInstance().addEvent(table, toHashMap(record));
144 | }
145 |
146 | @ReactMethod
147 | public void addEventWithCallback(ReadableMap record, String database, String table, final Callback onSuccess, final Callback onError) {
148 | TreasureData.sharedInstance().addEventWithCallback(database, table, toHashMap(record), new TDCallback() {
149 | @Override
150 | public void onSuccess() {
151 | onSuccess.invoke();
152 | }
153 |
154 | @Override
155 | public void onError(String errorCode, Exception e) {
156 | onError.invoke(errorCode, e.getMessage());
157 | }
158 | });
159 | }
160 |
161 | @ReactMethod
162 | public void addEventWithCallback(ReadableMap record, String table, final Callback onSuccess, final Callback onError) {
163 | TreasureData.sharedInstance().addEventWithCallback(table, toHashMap(record), new TDCallback() {
164 | @Override
165 | public void onSuccess() {
166 | onSuccess.invoke();
167 | }
168 |
169 | @Override
170 | public void onError(String errorCode, Exception e) {
171 | onError.invoke(errorCode, e.getMessage());
172 | }
173 | });
174 | }
175 |
176 | @ReactMethod
177 | public void uploadEvents() {
178 | TreasureData.sharedInstance().uploadEvents();
179 | }
180 |
181 | @ReactMethod
182 | public void uploadEventsWithCallback(final Callback onSuccess, final Callback onError) {
183 | TreasureData.sharedInstance().uploadEventsWithCallback(new TDCallback() {
184 | @Override
185 | public void onSuccess() {
186 | onSuccess.invoke();
187 | }
188 |
189 | @Override
190 | public void onError(String errorCode, Exception e) {
191 | onError.invoke(errorCode, e.getMessage());
192 | }
193 | });
194 | }
195 |
196 | @ReactMethod
197 | public void startSession() {
198 | TreasureData.startSession(getReactApplicationContext());
199 | }
200 |
201 | @ReactMethod
202 | public void startSession(String table) {
203 | TreasureData.sharedInstance().startSession(table);
204 | }
205 |
206 | @ReactMethod
207 | public void startSession(String table, String database) {
208 | TreasureData.sharedInstance().startSession(table, database);
209 | }
210 |
211 | @ReactMethod
212 | public void endSession() {
213 | TreasureData.endSession(getReactApplicationContext());
214 | }
215 |
216 | @ReactMethod
217 | public void endSession(String table) {
218 | TreasureData.sharedInstance().endSession(table);
219 | }
220 |
221 | @ReactMethod
222 | public void endSession(String table, String database) {
223 | TreasureData.sharedInstance().endSession(table, database);
224 | }
225 |
226 | @ReactMethod
227 | public void getSessionId(Promise promise) {
228 | String sessionId = TreasureData.getSessionId(getReactApplicationContext());
229 | if (sessionId == null) {
230 | promise.reject(new Throwable("sessionId == null"));
231 | } else {
232 | promise.resolve(sessionId);
233 | }
234 | }
235 |
236 | @ReactMethod
237 | public void isFirstRun(Promise promise) {
238 | boolean isFirstRun = TreasureData.sharedInstance().isFirstRun(getReactApplicationContext());
239 | if (isFirstRun) {
240 | promise.resolve(null);
241 | } else {
242 | promise.reject(new Throwable("not first run"));
243 | }
244 | }
245 |
246 | @ReactMethod
247 | public void clearFirstRun() {
248 | TreasureData.sharedInstance().clearFirstRun(getReactApplicationContext());
249 | }
250 |
251 | @ReactMethod
252 | public void setSessionTimeoutMilli(long to) {
253 | TreasureData.setSessionTimeoutMilli(to);
254 | }
255 |
256 | @ReactMethod
257 | public void enableRetryUploading() {
258 | TreasureData.sharedInstance().enableAutoRetryUploading();
259 | }
260 |
261 | @ReactMethod
262 | public void disableRetryUploading() {
263 | TreasureData.sharedInstance().disableAutoRetryUploading();
264 | }
265 |
266 | @ReactMethod
267 | public void enableEventCompression() {
268 | TreasureData.enableEventCompression();
269 | }
270 |
271 | @ReactMethod
272 | public void disableEventCompression() {
273 | TreasureData.disableEventCompression();
274 | }
275 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/github/quipper/rn/td/RNTreasureDataPackage.java:
--------------------------------------------------------------------------------
1 | package com.github.quipper.rn.td;
2 |
3 | import java.util.Collections;
4 | import java.util.List;
5 |
6 | import com.facebook.react.ReactPackage;
7 | import com.facebook.react.bridge.NativeModule;
8 | import com.facebook.react.bridge.ReactApplicationContext;
9 | import com.facebook.react.uimanager.ViewManager;
10 | import com.facebook.react.bridge.JavaScriptModule;
11 |
12 | public final class RNTreasureDataPackage implements ReactPackage {
13 |
14 | @Override
15 | public List createNativeModules(ReactApplicationContext reactContext) {
16 | return Collections.singletonList(new RNTreasureDataModule(reactContext));
17 | }
18 |
19 | // Deprecated from RN 0.47
20 | public List> createJSModules() {
21 | return Collections.emptyList();
22 | }
23 |
24 | @Override
25 | public List createViewManagers(ReactApplicationContext reactContext) {
26 | return Collections.emptyList();
27 | }
28 | }
--------------------------------------------------------------------------------
/android/src/main/java/com/github/quipper/rn/td/Utils.java:
--------------------------------------------------------------------------------
1 | package com.github.quipper.rn.td;
2 |
3 | import com.facebook.react.bridge.ReadableArray;
4 | import com.facebook.react.bridge.ReadableMap;
5 | import com.facebook.react.bridge.ReadableMapKeySetIterator;
6 |
7 | import java.util.ArrayList;
8 | import java.util.HashMap;
9 |
10 | final class Utils {
11 |
12 | private Utils() {
13 | throw new AssertionError();
14 | }
15 |
16 | // https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeMap.java#L61
17 | static HashMap toHashMap(ReadableMap map) {
18 | HashMap hashMap = new HashMap<>();
19 | ReadableMapKeySetIterator iterator = map.keySetIterator();
20 | while (iterator.hasNextKey()) {
21 | String key = iterator.nextKey();
22 | switch (map.getType(key)) {
23 | case Null:
24 | hashMap.put(key, null);
25 | break;
26 | case Boolean:
27 | hashMap.put(key, map.getBoolean(key));
28 | break;
29 | case Number:
30 | hashMap.put(key, map.getDouble(key));
31 | break;
32 | case String:
33 | hashMap.put(key, map.getString(key));
34 | break;
35 | case Map:
36 | hashMap.put(key,toHashMap(map.getMap(key)));
37 | break;
38 | case Array:
39 | hashMap.put(key, toArrayList(map.getArray(key)));
40 | break;
41 | default:
42 | throw new IllegalArgumentException("Could not convert object with key: " + key + ".");
43 | }
44 | }
45 | return hashMap;
46 | }
47 |
48 | // https://github.com/facebook/react-native/blob/1e8f3b11027fe0a7514b4fc97d0798d3c64bc895/ReactAndroid/src/main/java/com/facebook/react/bridge/ReadableNativeArray.java#L56
49 | private static ArrayList