Skip to content

Commit

Permalink
Merge pull request #400 from wyne/abstraction
Browse files Browse the repository at this point in the history
Better swipe analytics
  • Loading branch information
wyne authored Mar 22, 2024
2 parents 37150c2 + 4774d43 commit 82f14b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
6 changes: 4 additions & 2 deletions src/components/Interactions/HalfTap/HalfTileTouchSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ export const HalfTileTouchSurface: React.FunctionComponent<Props> = (
setParticles((particles) => [...particles, { key, value }]);
};

const scoreChangeHandler = (addend: number) => {
const scoreChangeHandler = (addend: number, powerHold = false) => {
if (currentGame.locked) return;

if (showPointParticles) {
Expand All @@ -61,6 +61,8 @@ export const HalfTileTouchSurface: React.FunctionComponent<Props> = (
addend: addend,
round: roundCurrent,
type: scoreType,
power_hold: powerHold,
interaction: 'half-tap',
});
dispatch(playerRoundScoreIncrement(playerId, roundCurrent, scoreType == 'increment' ? addend : -addend));
};
Expand All @@ -71,7 +73,7 @@ export const HalfTileTouchSurface: React.FunctionComponent<Props> = (
underlayColor={currentGame.locked ? 'transparent' : fontColor + '30'}
activeOpacity={1}
onPress={() => scoreChangeHandler(addendOne)}
onLongPress={() => scoreChangeHandler(addendTwo)}>
onLongPress={() => scoreChangeHandler(addendTwo, true)}>
<View style={[StyleSheet.absoluteFill]}>
{particles.map((particle) => (
<ScoreParticle key={particle.key} id={particle.key} value={particle.value} />
Expand Down
26 changes: 15 additions & 11 deletions src/components/Interactions/Swipe/Swipe.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ interface HalfTapProps {
playerId: string;
}

const notchSize = 50;

const SwipeVertical: React.FC<HalfTapProps> = ({
children,
index,
Expand Down Expand Up @@ -151,6 +153,17 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
// Handle the end of the gesture
totalOffset.value = null;

analytics().logEvent('score_change', {
player_index: index,
game_id: currentGameId,
addend: powerHold ? addendOne : addendTwo,
round: roundCurrent,
type: event.nativeEvent.translationY > 0 ? 'decrement' : 'increment',
power_hold: powerHold,
notches: Math.round((event.nativeEvent.translationY || 0) / notchSize),
interaction: 'swipe-vertical',
});

// Spring the animation back to the start
Animated.spring(pan, {
toValue: { x: 0, y: 0 },
Expand All @@ -177,15 +190,6 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
Haptics.impactAsync(Haptics.ImpactFeedbackStyle.Light);
}

analytics().logEvent('score_change', {
player_index: index,
game_id: currentGameId,
addend: Math.abs(a),
round: roundCurrent,
type: a > 0 ? 'increment' : 'decrement',
interaction: 'swipe-vertical',
});

dispatch(playerRoundScoreIncrement(playerId, roundCurrent, a));
};

Expand All @@ -196,8 +200,8 @@ const SwipeVertical: React.FC<HalfTapProps> = ({
(currentValue, previousValue) => {
if (currentValue === null) return;

const c = Math.round((currentValue || 0) / 50);
const p = Math.round((previousValue || 0) / 50);
const c = Math.round((currentValue || 0) / notchSize);
const p = Math.round((previousValue || 0) / notchSize);
if (c - p !== 0) {
runOnJS(scoreChangeHandler)(c - p);
}
Expand Down

0 comments on commit 82f14b1

Please sign in to comment.