react-native-tinykit 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +107 -1
- package/Tinykit.podspec +1 -1
- package/ios/Tinykit.h +1 -1
- package/ios/Tinykit.mm +60 -0
- package/lib/module/NativeTinykit.js +13 -0
- package/lib/module/NativeTinykit.js.map +1 -1
- package/lib/module/index.js +26 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/NativeTinykit.d.ts +17 -1
- package/lib/typescript/src/NativeTinykit.d.ts.map +1 -1
- package/lib/typescript/src/index.d.ts +21 -0
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +2 -2
- package/src/NativeTinykit.ts +23 -1
- package/src/index.tsx +37 -1
package/README.md
CHANGED
|
@@ -3,11 +3,14 @@
|
|
|
3
3
|
[](https://www.npmjs.com/package/react-native-tinykit)
|
|
4
4
|
[](https://github.com/luoxuhai/react-native-tinykit/blob/master/LICENSE)
|
|
5
5
|
|
|
6
|
-
A lightweight React Native toolkit for iOS, providing essential native utilities.
|
|
6
|
+
A lightweight React Native toolkit for iOS, providing essential native utilities (Zero dependencies).
|
|
7
|
+
|
|
8
|
+
<img src="./assets/example.png" width="400" />
|
|
7
9
|
|
|
8
10
|
## Features
|
|
9
11
|
|
|
10
12
|
- 🔄 **App Restart** - Programmatically restart your React Native application
|
|
13
|
+
- 🌡️ **Thermal State** - Get and monitor the device's thermal state
|
|
11
14
|
- ⚡ **Turbo Module** - Built with the new architecture for optimal performance
|
|
12
15
|
- 📦 **Lightweight** - Minimal footprint with zero dependencies
|
|
13
16
|
|
|
@@ -51,6 +54,47 @@ restart();
|
|
|
51
54
|
- Reset app state after logout
|
|
52
55
|
- Apply configuration changes that require a restart
|
|
53
56
|
|
|
57
|
+
### Thermal State
|
|
58
|
+
|
|
59
|
+
Get the current thermal state and monitor for changes:
|
|
60
|
+
|
|
61
|
+
```tsx
|
|
62
|
+
import { getThermalState, addThermalStateListener } from 'react-native-tinykit';
|
|
63
|
+
|
|
64
|
+
// Get current thermal state
|
|
65
|
+
const state = getThermalState();
|
|
66
|
+
console.log('Current thermal state:', state);
|
|
67
|
+
|
|
68
|
+
// Listen for thermal state changes
|
|
69
|
+
const subscription = addThermalStateListener((state) => {
|
|
70
|
+
console.log('Thermal state changed:', state);
|
|
71
|
+
|
|
72
|
+
switch (state) {
|
|
73
|
+
case 'nominal':
|
|
74
|
+
// Normal operating conditions
|
|
75
|
+
break;
|
|
76
|
+
case 'fair':
|
|
77
|
+
// Slightly elevated thermal state
|
|
78
|
+
break;
|
|
79
|
+
case 'serious':
|
|
80
|
+
// High thermal state - consider reducing activity
|
|
81
|
+
break;
|
|
82
|
+
case 'critical':
|
|
83
|
+
// Critical thermal state - reduce activity immediately
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
// Clean up the listener when done
|
|
89
|
+
subscription.remove();
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
#### Example Use Cases
|
|
93
|
+
|
|
94
|
+
- Reduce graphics quality or frame rate when device is overheating
|
|
95
|
+
- Pause background tasks during high thermal states
|
|
96
|
+
- Show warnings to users when thermal state is critical
|
|
97
|
+
|
|
54
98
|
## API Reference
|
|
55
99
|
|
|
56
100
|
### `restart()`
|
|
@@ -72,6 +116,68 @@ const handleLogout = async () => {
|
|
|
72
116
|
};
|
|
73
117
|
```
|
|
74
118
|
|
|
119
|
+
### `getThermalState()`
|
|
120
|
+
|
|
121
|
+
Returns the current thermal state of the device.
|
|
122
|
+
|
|
123
|
+
```tsx
|
|
124
|
+
getThermalState(): ThermalState
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
**Returns:** `'nominal' | 'fair' | 'serious' | 'critical'`
|
|
128
|
+
|
|
129
|
+
| State | Description |
|
|
130
|
+
| ---------- | ----------------------------------------- |
|
|
131
|
+
| `nominal` | The thermal state is within normal limits |
|
|
132
|
+
| `fair` | The thermal state is slightly elevated |
|
|
133
|
+
| `serious` | The thermal state is high |
|
|
134
|
+
| `critical` | The thermal state is critically high |
|
|
135
|
+
|
|
136
|
+
**Example:**
|
|
137
|
+
|
|
138
|
+
```tsx
|
|
139
|
+
import { getThermalState } from 'react-native-tinykit';
|
|
140
|
+
|
|
141
|
+
const state = getThermalState();
|
|
142
|
+
if (state === 'critical') {
|
|
143
|
+
// Reduce app activity to help cool down the device
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### `addThermalStateListener()`
|
|
148
|
+
|
|
149
|
+
Adds a listener for thermal state changes.
|
|
150
|
+
|
|
151
|
+
```tsx
|
|
152
|
+
addThermalStateListener(listener: (state: ThermalState) => void): { remove: () => void }
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
**Parameters:**
|
|
156
|
+
|
|
157
|
+
- `listener` - Callback function that receives the new thermal state
|
|
158
|
+
|
|
159
|
+
**Returns:** A subscription object with a `remove()` method to stop listening
|
|
160
|
+
|
|
161
|
+
**Example:**
|
|
162
|
+
|
|
163
|
+
```tsx
|
|
164
|
+
import { addThermalStateListener } from 'react-native-tinykit';
|
|
165
|
+
|
|
166
|
+
const subscription = addThermalStateListener((state) => {
|
|
167
|
+
console.log('Thermal state changed to:', state);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Later, when you want to stop listening:
|
|
171
|
+
subscription.remove();
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Apps Using This Library
|
|
175
|
+
|
|
176
|
+
- [Night Vision - LiDAR Camera](https://apps.apple.com/app/id1668629667)
|
|
177
|
+
- [Laser Measure - LiDAR Powered](https://apps.apple.com/app/id6466744678)
|
|
178
|
+
- [PhoneAway - Digital Detox](https://apps.apple.com/app/id6744548607)
|
|
179
|
+
- [Fatigue Alert - Stay Awake](https://apps.apple.com/app/id6479893638)
|
|
180
|
+
|
|
75
181
|
## Contributing
|
|
76
182
|
|
|
77
183
|
See the [contributing guide](CONTRIBUTING.md) to learn how to contribute to the repository and the development workflow.
|
package/Tinykit.podspec
CHANGED
|
@@ -3,7 +3,7 @@ require "json"
|
|
|
3
3
|
package = JSON.parse(File.read(File.join(__dir__, "package.json")))
|
|
4
4
|
|
|
5
5
|
Pod::Spec.new do |s|
|
|
6
|
-
s.name = "
|
|
6
|
+
s.name = "react-native-tinykit"
|
|
7
7
|
s.version = package["version"]
|
|
8
8
|
s.summary = package["description"]
|
|
9
9
|
s.homepage = package["homepage"]
|
package/ios/Tinykit.h
CHANGED
package/ios/Tinykit.mm
CHANGED
|
@@ -3,18 +3,78 @@
|
|
|
3
3
|
|
|
4
4
|
@implementation Tinykit
|
|
5
5
|
|
|
6
|
+
/// Initializes the Tinykit module and registers for thermal state change notifications.
|
|
7
|
+
- (instancetype)init
|
|
8
|
+
{
|
|
9
|
+
self = [super init];
|
|
10
|
+
if (self) {
|
|
11
|
+
[[NSNotificationCenter defaultCenter] addObserver:self
|
|
12
|
+
selector:@selector(thermalStateChange:)
|
|
13
|
+
name:NSProcessInfoThermalStateDidChangeNotification
|
|
14
|
+
object:nil];
|
|
15
|
+
}
|
|
16
|
+
return self;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/// Cleans up by removing the observer from the notification center.
|
|
20
|
+
- (void)dealloc
|
|
21
|
+
{
|
|
22
|
+
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/// Converts a thermal state enum value to its string representation.
|
|
26
|
+
/// @param thermalState The thermal state to convert.
|
|
27
|
+
/// @return A string representation of the thermal state ("nominal", "fair", "serious", or "critical").
|
|
28
|
+
+ (NSString *)thermalStateToString:(NSProcessInfoThermalState)thermalState
|
|
29
|
+
{
|
|
30
|
+
switch (thermalState) {
|
|
31
|
+
case NSProcessInfoThermalStateNominal:
|
|
32
|
+
return @"nominal";
|
|
33
|
+
case NSProcessInfoThermalStateFair:
|
|
34
|
+
return @"fair";
|
|
35
|
+
case NSProcessInfoThermalStateSerious:
|
|
36
|
+
return @"serious";
|
|
37
|
+
case NSProcessInfoThermalStateCritical:
|
|
38
|
+
return @"critical";
|
|
39
|
+
default:
|
|
40
|
+
return @"nominal";
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/// Handles thermal state change notifications from the system.
|
|
45
|
+
/// @param notification The notification containing thermal state change information.
|
|
46
|
+
- (void)thermalStateChange:(NSNotification *)notification
|
|
47
|
+
{
|
|
48
|
+
NSString *state = [Tinykit thermalStateToString:[[NSProcessInfo processInfo] thermalState]];
|
|
49
|
+
[self emitOnThermalStateChange:@{@"thermalState": state}];
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/// Returns the current thermal state of the device as a string.
|
|
53
|
+
/// @return A string representation of the current thermal state.
|
|
54
|
+
- (NSString *)getThermalState
|
|
55
|
+
{
|
|
56
|
+
NSProcessInfoThermalState thermalState = [[NSProcessInfo processInfo] thermalState];
|
|
57
|
+
return [Tinykit thermalStateToString:thermalState];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/// Triggers a reload of the React Native bundle on the main thread.
|
|
6
61
|
- (void)restart {
|
|
7
62
|
dispatch_sync(dispatch_get_main_queue(), ^{
|
|
8
63
|
RCTTriggerReloadCommandListeners(@"react-native-tinykit");
|
|
9
64
|
});
|
|
10
65
|
}
|
|
11
66
|
|
|
67
|
+
/// Returns the TurboModule instance for this native module.
|
|
68
|
+
/// @param params The initialization parameters for the TurboModule.
|
|
69
|
+
/// @return A shared pointer to the TurboModule instance.
|
|
12
70
|
- (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
|
|
13
71
|
(const facebook::react::ObjCTurboModule::InitParams &)params
|
|
14
72
|
{
|
|
15
73
|
return std::make_shared<facebook::react::NativeTinykitSpecJSI>(params);
|
|
16
74
|
}
|
|
17
75
|
|
|
76
|
+
/// Returns the name of this native module used for JavaScript bridge registration.
|
|
77
|
+
/// @return The module name "Tinykit".
|
|
18
78
|
+ (NSString *)moduleName
|
|
19
79
|
{
|
|
20
80
|
return @"Tinykit";
|
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import { TurboModuleRegistry } from 'react-native';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Thermal state values that indicate the current thermal condition of the device.
|
|
7
|
+
* - 'nominal': The thermal state is within normal limits.
|
|
8
|
+
* - 'fair': The thermal state is slightly elevated.
|
|
9
|
+
* - 'serious': The thermal state is high.
|
|
10
|
+
* - 'critical': The thermal state is critically high.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Event payload for thermal state change events.
|
|
15
|
+
*/
|
|
16
|
+
|
|
4
17
|
export default TurboModuleRegistry.getEnforcing('Tinykit');
|
|
5
18
|
//# sourceMappingURL=NativeTinykit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeTinykit.ts"],"mappings":";;AAAA,
|
|
1
|
+
{"version":3,"names":["TurboModuleRegistry","getEnforcing"],"sourceRoot":"../../src","sources":["NativeTinykit.ts"],"mappings":";;AAAA,SACEA,mBAAmB,QAGd,cAAc;;AAErB;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA;AACA;AACA;;AAWA,eAAeA,mBAAmB,CAACC,YAAY,CAAO,SAAS,CAAC","ignoreList":[]}
|
package/lib/module/index.js
CHANGED
|
@@ -1,11 +1,36 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
import Tinykit from "./NativeTinykit.js";
|
|
4
|
-
|
|
5
4
|
/**
|
|
6
5
|
* Restarts the React Native application.
|
|
7
6
|
*/
|
|
8
7
|
export function restart() {
|
|
9
8
|
return Tinykit.restart();
|
|
10
9
|
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Gets the current thermal state of the device.
|
|
13
|
+
*
|
|
14
|
+
* @returns The current thermal state: 'nominal', 'fair', 'serious', or 'critical'
|
|
15
|
+
*/
|
|
16
|
+
export function getThermalState() {
|
|
17
|
+
return Tinykit.getThermalState();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Callback function type for thermal state change events.
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Adds a listener that will be called when the thermal state changes.
|
|
26
|
+
*
|
|
27
|
+
* @param listener - Callback function that receives the new thermal state
|
|
28
|
+
* @returns A subscription object with a remove method to stop listening
|
|
29
|
+
*/
|
|
30
|
+
export function addThermalStateListener(listener) {
|
|
31
|
+
const subscription = Tinykit.onThermalStateChange(event => {
|
|
32
|
+
listener(event.thermalState);
|
|
33
|
+
});
|
|
34
|
+
return subscription;
|
|
35
|
+
}
|
|
11
36
|
//# sourceMappingURL=index.js.map
|
package/lib/module/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["Tinykit","restart"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,OAAO,
|
|
1
|
+
{"version":3,"names":["Tinykit","restart","getThermalState","addThermalStateListener","listener","subscription","onThermalStateChange","event","thermalState"],"sourceRoot":"../../src","sources":["index.tsx"],"mappings":";;AAAA,OAAOA,OAAO,MAGP,oBAAiB;AAIxB;AACA;AACA;AACA,OAAO,SAASC,OAAOA,CAAA,EAAS;EAC9B,OAAOD,OAAO,CAACC,OAAO,CAAC,CAAC;AAC1B;;AAEA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAA,EAAiB;EAC9C,OAAOF,OAAO,CAACE,eAAe,CAAC,CAAC;AAClC;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,uBAAuBA,CAACC,QAA8B,EAEpE;EACA,MAAMC,YAAY,GAAGL,OAAO,CAACM,oBAAoB,CAC9CC,KAA8B,IAAK;IAClCH,QAAQ,CAACG,KAAK,CAACC,YAAY,CAAC;EAC9B,CACF,CAAC;EACD,OAAOH,YAAY;AACrB","ignoreList":[]}
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
import { type TurboModule } from 'react-native';
|
|
1
|
+
import { type TurboModule, type CodegenTypes } from 'react-native';
|
|
2
|
+
/**
|
|
3
|
+
* Thermal state values that indicate the current thermal condition of the device.
|
|
4
|
+
* - 'nominal': The thermal state is within normal limits.
|
|
5
|
+
* - 'fair': The thermal state is slightly elevated.
|
|
6
|
+
* - 'serious': The thermal state is high.
|
|
7
|
+
* - 'critical': The thermal state is critically high.
|
|
8
|
+
*/
|
|
9
|
+
export type ThermalState = 'nominal' | 'fair' | 'serious' | 'critical';
|
|
10
|
+
/**
|
|
11
|
+
* Event payload for thermal state change events.
|
|
12
|
+
*/
|
|
13
|
+
export type ThermalStateChangeEvent = {
|
|
14
|
+
thermalState: ThermalState;
|
|
15
|
+
};
|
|
2
16
|
export interface Spec extends TurboModule {
|
|
3
17
|
restart(): void;
|
|
18
|
+
getThermalState(): ThermalState;
|
|
19
|
+
readonly onThermalStateChange: CodegenTypes.EventEmitter<ThermalStateChangeEvent>;
|
|
4
20
|
}
|
|
5
21
|
declare const _default: Spec;
|
|
6
22
|
export default _default;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"NativeTinykit.d.ts","sourceRoot":"","sources":["../../../src/NativeTinykit.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"NativeTinykit.d.ts","sourceRoot":"","sources":["../../../src/NativeTinykit.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,WAAW,EAChB,KAAK,YAAY,EAClB,MAAM,cAAc,CAAC;AAEtB;;;;;;GAMG;AACH,MAAM,MAAM,YAAY,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,GAAG,UAAU,CAAC;AAEvE;;GAEG;AACH,MAAM,MAAM,uBAAuB,GAAG;IACpC,YAAY,EAAE,YAAY,CAAC;CAC5B,CAAC;AAEF,MAAM,WAAW,IAAK,SAAQ,WAAW;IACvC,OAAO,IAAI,IAAI,CAAC;IAChB,eAAe,IAAI,YAAY,CAAC;IAChC,QAAQ,CAAC,oBAAoB,EAAE,YAAY,CAAC,YAAY,CAAC,uBAAuB,CAAC,CAAC;CACnF;;AAED,wBAAiE"}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
|
+
import { type ThermalState } from './NativeTinykit';
|
|
2
|
+
export type { ThermalState, ThermalStateChangeEvent } from './NativeTinykit';
|
|
1
3
|
/**
|
|
2
4
|
* Restarts the React Native application.
|
|
3
5
|
*/
|
|
4
6
|
export declare function restart(): void;
|
|
7
|
+
/**
|
|
8
|
+
* Gets the current thermal state of the device.
|
|
9
|
+
*
|
|
10
|
+
* @returns The current thermal state: 'nominal', 'fair', 'serious', or 'critical'
|
|
11
|
+
*/
|
|
12
|
+
export declare function getThermalState(): ThermalState;
|
|
13
|
+
/**
|
|
14
|
+
* Callback function type for thermal state change events.
|
|
15
|
+
*/
|
|
16
|
+
export type ThermalStateListener = (state: ThermalState) => void;
|
|
17
|
+
/**
|
|
18
|
+
* Adds a listener that will be called when the thermal state changes.
|
|
19
|
+
*
|
|
20
|
+
* @param listener - Callback function that receives the new thermal state
|
|
21
|
+
* @returns A subscription object with a remove method to stop listening
|
|
22
|
+
*/
|
|
23
|
+
export declare function addThermalStateListener(listener: ThermalStateListener): {
|
|
24
|
+
remove: () => void;
|
|
25
|
+
};
|
|
5
26
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.tsx"],"names":[],"mappings":"AAAA,OAAgB,EACd,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAC;AAEzB,YAAY,EAAE,YAAY,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAE7E;;GAEG;AACH,wBAAgB,OAAO,IAAI,IAAI,CAE9B;AAED;;;;GAIG;AACH,wBAAgB,eAAe,IAAI,YAAY,CAE9C;AAED;;GAEG;AACH,MAAM,MAAM,oBAAoB,GAAG,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;AAEjE;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,oBAAoB,GAAG;IACvE,MAAM,EAAE,MAAM,IAAI,CAAC;CACpB,CAOA"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-tinykit",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "A lightweight React Native toolkit for iOS, providing essential native utilities (Zero dependencies)",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
7
7
|
"exports": {
|
package/src/NativeTinykit.ts
CHANGED
|
@@ -1,7 +1,29 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
TurboModuleRegistry,
|
|
3
|
+
type TurboModule,
|
|
4
|
+
type CodegenTypes,
|
|
5
|
+
} from 'react-native';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Thermal state values that indicate the current thermal condition of the device.
|
|
9
|
+
* - 'nominal': The thermal state is within normal limits.
|
|
10
|
+
* - 'fair': The thermal state is slightly elevated.
|
|
11
|
+
* - 'serious': The thermal state is high.
|
|
12
|
+
* - 'critical': The thermal state is critically high.
|
|
13
|
+
*/
|
|
14
|
+
export type ThermalState = 'nominal' | 'fair' | 'serious' | 'critical';
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Event payload for thermal state change events.
|
|
18
|
+
*/
|
|
19
|
+
export type ThermalStateChangeEvent = {
|
|
20
|
+
thermalState: ThermalState;
|
|
21
|
+
};
|
|
2
22
|
|
|
3
23
|
export interface Spec extends TurboModule {
|
|
4
24
|
restart(): void;
|
|
25
|
+
getThermalState(): ThermalState;
|
|
26
|
+
readonly onThermalStateChange: CodegenTypes.EventEmitter<ThermalStateChangeEvent>;
|
|
5
27
|
}
|
|
6
28
|
|
|
7
29
|
export default TurboModuleRegistry.getEnforcing<Spec>('Tinykit');
|
package/src/index.tsx
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import Tinykit
|
|
1
|
+
import Tinykit, {
|
|
2
|
+
type ThermalState,
|
|
3
|
+
type ThermalStateChangeEvent,
|
|
4
|
+
} from './NativeTinykit';
|
|
5
|
+
|
|
6
|
+
export type { ThermalState, ThermalStateChangeEvent } from './NativeTinykit';
|
|
2
7
|
|
|
3
8
|
/**
|
|
4
9
|
* Restarts the React Native application.
|
|
@@ -6,3 +11,34 @@ import Tinykit from './NativeTinykit';
|
|
|
6
11
|
export function restart(): void {
|
|
7
12
|
return Tinykit.restart();
|
|
8
13
|
}
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Gets the current thermal state of the device.
|
|
17
|
+
*
|
|
18
|
+
* @returns The current thermal state: 'nominal', 'fair', 'serious', or 'critical'
|
|
19
|
+
*/
|
|
20
|
+
export function getThermalState(): ThermalState {
|
|
21
|
+
return Tinykit.getThermalState();
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Callback function type for thermal state change events.
|
|
26
|
+
*/
|
|
27
|
+
export type ThermalStateListener = (state: ThermalState) => void;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Adds a listener that will be called when the thermal state changes.
|
|
31
|
+
*
|
|
32
|
+
* @param listener - Callback function that receives the new thermal state
|
|
33
|
+
* @returns A subscription object with a remove method to stop listening
|
|
34
|
+
*/
|
|
35
|
+
export function addThermalStateListener(listener: ThermalStateListener): {
|
|
36
|
+
remove: () => void;
|
|
37
|
+
} {
|
|
38
|
+
const subscription = Tinykit.onThermalStateChange(
|
|
39
|
+
(event: ThermalStateChangeEvent) => {
|
|
40
|
+
listener(event.thermalState);
|
|
41
|
+
}
|
|
42
|
+
);
|
|
43
|
+
return subscription;
|
|
44
|
+
}
|