Replace usage of deprecated DeviceEventEmitter - 1.155 🚀

This commit is contained in:
Brandon Presley 2023-09-04 14:20:36 +12:00
parent c9773af92d
commit c480d3e382
8 changed files with 17 additions and 13 deletions

View File

@ -4,7 +4,7 @@ import {
NavigationContainer,
} from "@react-navigation/native";
import React, { useEffect, useMemo, useState } from "react";
import { DeviceEventEmitter, useColorScheme } from "react-native";
import { useColorScheme } from "react-native";
import {
MD3DarkTheme as PaperDarkTheme,
MD3LightTheme as PaperDefaultTheme,
@ -14,6 +14,7 @@ import {
import MaterialIcon from "react-native-vector-icons/MaterialIcons";
import { AppDataSource } from "./data-source";
import { settingsRepo } from "./db";
import { emitter } from "./emitter";
import Routes from "./Routes";
import { TOAST } from "./toast";
import { ThemeContext } from "./use-theme";
@ -59,7 +60,7 @@ const App = () => {
if (settings.darkColor) setDarkColor(settings.darkColor);
setInitialized(true);
})();
const description = DeviceEventEmitter.addListener(
const description = emitter.addListener(
TOAST,
({ value }: { value: string }) => {
setSnackbar(value);

View File

@ -6,12 +6,13 @@ import {
useRoute,
} from "@react-navigation/native";
import { useCallback, useEffect, useState } from "react";
import { DeviceEventEmitter, FlatList } from "react-native";
import { FlatList } from "react-native";
import { List } from "react-native-paper";
import { Like } from "typeorm";
import { LIMIT } from "./constants";
import { getNow, setRepo, settingsRepo } from "./db";
import DrawerHeader from "./DrawerHeader";
import { emitter } from "./emitter";
import GymSet, { defaultSet } from "./gym-set";
import { HomePageParams } from "./home-page-params";
import ListMenu from "./ListMenu";
@ -58,7 +59,7 @@ export default function SetList() {
useEffect(() => {
settingsRepo.findOne({ where: {} }).then(setSettings);
const description = DeviceEventEmitter.addListener(SETTINGS, () => {
const description = emitter.addListener(SETTINGS, () => {
settingsRepo.findOne({ where: {} }).then(setSettings);
});
return description.remove;

View File

@ -85,8 +85,8 @@ android {
applicationId "com.massive"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 36180
versionName "1.154"
versionCode 36181
versionName "1.155"
}
signingConfigs {
release {

3
emitter.ts Normal file
View File

@ -0,0 +1,3 @@
import { NativeEventEmitter, NativeModules } from "react-native";
export const emitter = new NativeEventEmitter(NativeModules.Emitter);

View File

@ -1,6 +1,6 @@
{
"name": "massive",
"version": "1.154",
"version": "1.155",
"private": true,
"license": "GPL-3.0-only",
"scripts": {

View File

@ -1,5 +1,5 @@
import { Column, Entity, PrimaryColumn } from "typeorm";
import { DeviceEventEmitter } from "react-native";
import { emitter } from "./emitter";
@Entity()
export default class Settings {
@ -52,5 +52,5 @@ export default class Settings {
export const SETTINGS = "settings";
export const settingsUpdated = () => {
DeviceEventEmitter.emit(SETTINGS);
emitter.emit(SETTINGS);
};

View File

@ -1,7 +1,7 @@
import { DeviceEventEmitter } from "react-native";
import { emitter } from "./emitter";
export const TOAST = "toast";
export function toast(value: string) {
DeviceEventEmitter.emit(TOAST, { value });
emitter.emit(TOAST, { value });
}

View File

@ -1,6 +1,6 @@
import { useFocusEffect } from "@react-navigation/native";
import { useCallback, useState } from "react";
import { NativeEventEmitter } from "react-native";
import { emitter } from "./emitter";
import { TickEvent } from "./TimerPage";
export default function useTimer() {
@ -11,7 +11,6 @@ export default function useTimer() {
useCallback(() => {
setMinutes("00");
setSeconds("00");
const emitter = new NativeEventEmitter();
const listener = emitter.addListener("tick", (event: TickEvent) => {
console.log(`${useTimer.name}.tick:`, { event });
setMinutes(event.minutes);