react-native-tinykit
v0.6.0
Published
A lightweight React Native toolkit for iOS, providing essential native utilities (Zero dependencies)
Downloads
71
Readme
react-native-tinykit
A lightweight React Native toolkit for iOS, providing essential native utilities (Zero dependencies).
Features
- 🔄 App Restart - Programmatically restart your React Native application
- 🌡️ Thermal State - Get and monitor the device's thermal state
- ⭐ App Review - Request App Store review from within your app
- 🔅 Keep Awake - Prevent the screen from auto-locking
- 📳 Haptic Feedback - Trigger impact, selection, and notification haptics
- ⚡ Turbo Module - Built with the new architecture for optimal performance
- 📦 Lightweight - Minimal footprint with zero dependencies
Requirements
- React Native >= 0.76
- iOS only (for now)
Installation
# Using npm
npm install react-native-tinykit
# Using yarn
yarn add react-native-tinykitiOS Setup
cd ios && pod installUsage
Restart Application
Restart the React Native application programmatically:
import { restart } from 'react-native-tinykit';
// Restart the app
restart();Example Use Cases
- Force reload after language/locale change
- Reset app state after logout
- Apply configuration changes that require a restart
Thermal State
Get the current thermal state and monitor for changes:
import { getThermalState, onThermalStateChange } from 'react-native-tinykit';
// Get current thermal state
const state = getThermalState();
console.log('Current thermal state:', state);
// Listen for thermal state changes
const subscription = onThermalStateChange((state) => {
console.log('Thermal state changed:', state);
switch (state) {
case 'nominal':
// Normal operating conditions
break;
case 'fair':
// Slightly elevated thermal state
break;
case 'serious':
// High thermal state - consider reducing activity
break;
case 'critical':
// Critical thermal state - reduce activity immediately
break;
}
});
// Clean up the listener when done
subscription.remove();Example Use Cases
- Reduce graphics quality or frame rate when device is overheating
- Pause background tasks during high thermal states
- Show warnings to users when thermal state is critical
Keep Awake
Prevent the screen from auto-locking:
import {
activate,
deactivate,
useKeepAwake,
KeepAwake,
} from 'react-native-tinykit';
// Imperative API
activate(); // Keep screen awake
deactivate(); // Allow screen to auto-lock
// Hook - keeps screen awake while the component is mounted
function VideoPlayer() {
useKeepAwake();
return <Video />;
}
// Component - keeps screen awake while mounted
function App() {
return (
<>
<KeepAwake />
<MyContent />
</>
);
}Example Use Cases
- Keep the screen on during video playback
- Prevent auto-lock during navigation or long-running tasks
- Keep display active during presentations or reading
Haptic Feedback
Trigger haptic feedback with three types of generators:
import { impact, selection, notification } from 'react-native-tinykit';
// Impact feedback - physical "tap" sensation
impact('light');
impact('medium');
impact('heavy');
impact('soft');
impact('rigid');
// Selection feedback - subtle "tick" for selection changes
selection();
// Notification feedback - communicates success, warning, or error
notification('success');
notification('warning');
notification('error');Example Use Cases
- Provide tactile feedback on button press or toggle
- Indicate state changes with selection haptics
- Communicate action results (success/failure) with notification haptics
App Review
Request an App Store review from your user:
import { requestReview } from 'react-native-tinykit';
// Request review
await requestReview();Note: In development mode, the review dialog will always appear. In production (TestFlight/App Store), iOS limits the frequency of these prompts (max 3 times per year per user).
Example Use Cases
- Prompt for review after a user completes a significant action
- Ask for feedback after a certain number of app opens
API Reference
restart()
Triggers a reload of the React Native application.
restart(): voidExample:
import { restart } from 'react-native-tinykit';
const handleLogout = async () => {
await clearUserData();
restart(); // Restart app to reset state
};getThermalState()
Returns the current thermal state of the device.
getThermalState(): ThermalStateReturns: 'nominal' | 'fair' | 'serious' | 'critical'
| State | Description |
| ---------- | ----------------------------------------- |
| nominal | The thermal state is within normal limits |
| fair | The thermal state is slightly elevated |
| serious | The thermal state is high |
| critical | The thermal state is critically high |
Example:
import { getThermalState } from 'react-native-tinykit';
const state = getThermalState();
if (state === 'critical') {
// Reduce app activity to help cool down the device
}onThermalStateChange()
Adds a listener for thermal state changes.
onThermalStateChange(listener: (state: ThermalState) => void): { remove: () => void }Parameters:
listener- Callback function that receives the new thermal state
Returns: A subscription object with a remove() method to stop listening
Example:
import { onThermalStateChange } from 'react-native-tinykit';
const subscription = onThermalStateChange((state) => {
console.log('Thermal state changed to:', state);
});
// Later, when you want to stop listening:
subscription.remove();activate()
Activates the keep-awake feature, preventing the screen from auto-locking.
activate(): voidExample:
import { activate } from 'react-native-tinykit';
activate();deactivate()
Deactivates the keep-awake feature, allowing the screen to auto-lock.
deactivate(): voidExample:
import { deactivate } from 'react-native-tinykit';
deactivate();useKeepAwake()
A hook that keeps the screen awake while the component is mounted. Automatically deactivates on unmount.
useKeepAwake(): voidExample:
import { useKeepAwake } from 'react-native-tinykit';
function VideoPlayer() {
useKeepAwake();
return <Video />;
}<KeepAwake />
A component that keeps the screen awake while mounted. Renders nothing.
<KeepAwake />Example:
import { KeepAwake } from 'react-native-tinykit';
function App() {
const [isPlaying, setIsPlaying] = useState(false);
return (
<>
{isPlaying && <KeepAwake />}
<VideoPlayer onPlay={() => setIsPlaying(true)} />
</>
);
}impact()
Triggers an impact haptic feedback.
impact(style: ImpactFeedbackStyle): voidParameters:
style- The style of the impact feedback
| Style | Description |
| -------- | ------------------------------ |
| light | A light, subtle impact |
| medium | A medium impact (default feel) |
| heavy | A heavy, strong impact |
| soft | A soft, gentle impact |
| rigid | A rigid, firm impact |
Example:
import { impact } from 'react-native-tinykit';
const handlePress = () => {
impact('medium');
};selection()
Triggers a selection haptic feedback. Use this for selection changes like picking a value.
selection(): voidExample:
import { selection } from 'react-native-tinykit';
const handleSelectionChange = () => {
selection();
};notification()
Triggers a notification haptic feedback to communicate successes, failures, or warnings.
notification(type: NotificationFeedbackType): voidParameters:
type- The type of notification feedback
| Type | Description |
| --------- | --------------------------------------- |
| success | Indicates a task completed successfully |
| warning | Indicates a warning or caution |
| error | Indicates an error or failure |
Example:
import { notification } from 'react-native-tinykit';
const handleSubmit = async () => {
try {
await submitForm();
notification('success');
} catch {
notification('error');
}
};requestReview()
Requests a review of the app.
requestReview(): Promise<void>Returns: A Promise that resolves when the request is processed.
Example:
import { requestReview } from 'react-native-tinykit';
const handleReview = async () => {
try {
await requestReview();
} catch (error) {
console.error('Failed to request review:', error);
}
};Apps Using This Library
- Night Vision - LiDAR Camera
- Laser Measure - LiDAR Powered
- PhoneAway - Digital Detox
- Fatigue Alert - Stay Awake
Contributing
See the contributing guide to learn how to contribute to the repository and the development workflow.
License
MIT © Darkce
Made with create-react-native-library
