react-native-nai-timer
v0.2.5
Published
react-native-nai-timer
Readme
react-native-nai-timer
Native timer module for React Native apps using Nitro Modules.
Support
- Expo SDK 56 and newer
- iOS and Android native builds
- Requires
react-native-nitro-modules0.35.7 or newer - Not supported in Expo Go because this package includes native code
Installation
bun add react-native-nai-timer react-native-nitro-modulesFor npm projects:
npm install react-native-nai-timer react-native-nitro-modulesThen generate native projects or rebuild your development client:
npx expo prebuild
npx expo run:ios
npx expo run:androidUsage
import { useEffect, useState } from "react";
import { Text } from "react-native";
import { NaiTimer } from "react-native-nai-timer";
export function TimerDemo() {
const [seconds, setSeconds] = useState(0);
useEffect(() => {
const timerId = NaiTimer.setInterval(() => {
setSeconds((value) => value + 1);
}, 1000);
return () => {
NaiTimer.clearInterval(timerId);
};
}, []);
return <Text>{seconds}s</Text>;
}Available methods:
NaiTimer.setTimeout(callback, delay)NaiTimer.clearTimeout(id)NaiTimer.setInterval(callback, interval)NaiTimer.clearInterval(id)NaiTimer.clearAllTimers()
Example app
The repository includes an Expo example app with a visible timer demo:
bun install
bun run example startUse a development build or native simulator/device. Expo Go cannot load this native module.
Validation
From the repository root:
bun run lint
bun run typecheck
bun run build
bun run prebuild
bun run pods
bun run android:gradleNotes:
bun run prebuildregeneratesexample/iosandexample/androidfor local validation.- The native example folders are ignored and should not be committed.
bun run podsrequires CocoaPods and an iOS prebuild.bun run android:gradlerequires an Android prebuild and local Android build tooling.
