### Start React Native Metro Packager Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/CONTRIBUTING.md This command starts the Metro packager for the example application, allowing JavaScript code changes to be reflected without a rebuild. ```sh yarn example start ``` -------------------------------- ### Run React Native Example App on iOS Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/CONTRIBUTING.md Execute this command to build and run the example application on an iOS device or simulator. Native code changes will require a rebuild of the app. ```sh yarn example ios ``` -------------------------------- ### Run React Native Example App on Android Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/CONTRIBUTING.md Execute this command to build and run the example application on an Android device or emulator. Native code changes will require a rebuild of the app. ```sh yarn example android ``` -------------------------------- ### Install react-native-ringer-mode package Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/README.md Instructions to install the `react-native-ringer-mode` package using npm, which is required before utilizing its functionalities in a React Native project. ```sh npm install react-native-ringer-mode ``` -------------------------------- ### Install Project Dependencies with Yarn Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/CONTRIBUTING.md This command installs all required dependencies for the project's packages from the root directory. It is recommended to use Yarn over npm for development. ```sh yarn ``` -------------------------------- ### Get current ringer mode with React Native getRingerMode function Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/README.md Illustrates how to asynchronously fetch the current ringer mode of an Android device using the `getRingerMode` function. This example uses a `useEffect` hook to retrieve the mode when the component mounts and then displays it. ```js import React, { useEffect, useState } from 'react'; import { View, Text } from 'react-native'; import { RINGER_MODE, getRingerMode, RingerModeType, } from 'react-native-ringer-mode'; const modeText = { [RINGER_MODE.silent]: 'Silent', [RINGER_MODE.normal]: 'Normal', [RINGER_MODE.vibrate]: 'Vibrate', }; export default function App() { const [mode, setMode] = useState(); useEffect(() => { (async () => { try { const currentMode = await getRingerMode(); setMode(currentMode); } catch (error) { console.error(error); } })(); }, []); return ( Ringer Mode: {mode !== undefined ? modeText[mode] : null} ); } ``` -------------------------------- ### Get and set ringer mode using React Native useRingerMode hook Source: https://github.com/reyhankaplan/react-native-ringer-mode/blob/master/README.md Demonstrates how to use the `useRingerMode` hook in a React Native component to dynamically retrieve and update the device's ringer mode. This example displays the current mode and provides interactive buttons to change it, also showing any potential error messages. ```js import React from 'react'; import { View, Text, Button } from 'react-native'; import { useRingerMode, RINGER_MODE } from 'react-native-ringer-mode'; const modeText = { [RINGER_MODE.silent]: 'Silent', [RINGER_MODE.normal]: 'Normal', [RINGER_MODE.vibrate]: 'Vibrate', }; export default function App() { const { mode, error, setMode } = useRingerMode(); return ( Ringer Mode: {mode !== undefined ? modeText[mode] : null}