Skip to content

Commit

Permalink
fix: Debounce only on android
Browse files Browse the repository at this point in the history
* Use debounce only on android, apply on share.
  • Loading branch information
lukashaertel committed Sep 14, 2024
1 parent e951e75 commit 55b6aad
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 6 deletions.
6 changes: 4 additions & 2 deletions src/components/viewer/Viewer.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ import { captureException } from "@sentry/react-native";
import { Dimensions, Share } from "react-native";

import { conAbbr } from "../../configuration";
import { debounceOnAndroid } from "../../util/debounceOnAndroid";

export const shareImage = (url: string, title: string) =>
export const shareImage = debounceOnAndroid((url: string, title: string) =>
Share.share(
{
title,
url,
message: `Check out ${title} on ${conAbbr}!\n${url}`,
},
{},
).catch(captureException);
).catch(captureException),
);

export const minZoomFor = (width: number, height: number, padding: number) => {
if (width <= 0 || height <= 0) return 1;
Expand Down
7 changes: 5 additions & 2 deletions src/routes/dealers/Dealers.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { appBase, conAbbr } from "../../configuration";
import { useAppSelector } from "../../store";
import { selectDealerCategoryMapper } from "../../store/eurofurence/selectors/dealers";
import { DealerDetails } from "../../store/eurofurence/types";
import { debounceOnAndroid } from "../../util/debounceOnAndroid";

/**
* Compares category, checks if the categories are adult labeled.
Expand Down Expand Up @@ -177,12 +178,14 @@ export const useDealerAlphabeticalGroups = (t: TFunction, now: Moment, results:
return result;
}, [t, now, results, all]);
};
export const shareDealer = (dealer: DealerDetails) =>

export const shareDealer = debounceOnAndroid((dealer: DealerDetails) =>
Share.share(
{
title: dealer.DisplayNameOrAttendeeNickname,
url: `${appBase}/Web/Dealers/${dealer.Id}`,
message: `Check out ${dealer.DisplayNameOrAttendeeNickname} on ${conAbbr}!\n${appBase}/Web/Dealers/${dealer.Id}`,
},
{},
).catch(captureException);
).catch(captureException),
);
6 changes: 4 additions & 2 deletions src/routes/events/Events.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { EventDetailsInstance, eventInstanceForAny, eventInstanceForNotPassed, e
import { eventSectionForDate, eventSectionForHidden, eventSectionForPartOfDay, eventSectionForPassed, EventSectionProps } from "../../components/events/EventSection";
import { appBase, conAbbr } from "../../configuration";
import { EventDetails } from "../../store/eurofurence/types";
import { debounceOnAndroid } from "../../util/debounceOnAndroid";

/**
Returns a list of event instances according to conversion rules.
Expand Down Expand Up @@ -209,12 +210,13 @@ export const useEventOtherGroups = (t: TFunction, now: Moment, zone: string, all
}, [t, now, zone, all]);
};

export const shareEvent = (event: EventDetails) =>
export const shareEvent = debounceOnAndroid((event: EventDetails) =>
Share.share(
{
title: event.Title,
url: `${appBase}/Web/Events/${event.Id}`,
message: `Check out ${event.Title} on ${conAbbr}!\n${appBase}/Web/Events/${event.Id}`,
},
{},
).catch(captureException);
).catch(captureException),
);
12 changes: 12 additions & 0 deletions src/util/debounceOnAndroid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { debounce } from "lodash";
import { Platform } from "react-native";

/**
* Debounces the function only on Android.
* @param func The function to debounce
* @param wait The wait time if debouncing.
*/
export const debounceOnAndroid = <T extends (...args: any) => any>(func: T, wait: number = 1000) => {
if (Platform.OS === "ios") return func;
else return debounce(func, wait, { leading: false, trailing: false });
};

0 comments on commit 55b6aad

Please sign in to comment.