-
Notifications
You must be signed in to change notification settings - Fork 54
feat(pos-app): add BigAmountInput with per-character animations #400
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f167c8
feat(pos-app): add BigAmountInput with per-character animations
ignaciosantise 4523088
Merge origin/main into feat/amount-input-animation
ignaciosantise 2963345
Merge remote-tracking branch 'origin/main' into feat/amount-input-ani…
ignaciosantise 8bc57a0
feat(pos-app): add BigAmountInput with per-character animations
ignaciosantise 094fae3
Merge branch 'main' into feat/amount-input-animation
ignaciosantise 516e346
fix(pos-app): address PR review feedback for BigAmountInput
ignaciosantise File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
dapps/pos-app/components/big-amount-input/BigAmountInput.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import { StyleSheet, View } from "react-native"; | ||
| import type { BigAmountInputProps } from "./BigAmountInput.types"; | ||
| import { AnimatedNumber } from "./components/AnimatedNumber"; | ||
|
|
||
| /** | ||
| * Animated currency display with per-character animations. | ||
| * This is a display-only component - use with NumericKeyboard for input. | ||
| */ | ||
| export const BigAmountInput = ({ | ||
| value = "", | ||
| currency = "$", | ||
| symbolPosition = "left", | ||
| locale, | ||
| placeholder = "0.00", | ||
| isFocused = true, | ||
| cursorBlinkEnabled = true, | ||
| testID, | ||
| style, | ||
| }: BigAmountInputProps) => { | ||
| return ( | ||
| <View style={[styles.container, style]} testID={testID}> | ||
| <AnimatedNumber | ||
| value={value} | ||
| currency={currency} | ||
| symbolPosition={symbolPosition} | ||
| locale={locale} | ||
| placeholder={placeholder} | ||
| isFocused={isFocused} | ||
| cursorBlinkEnabled={cursorBlinkEnabled} | ||
| /> | ||
| </View> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| alignItems: "center", | ||
| justifyContent: "center", | ||
| minHeight: 80, | ||
| flex: 1, | ||
| width: "100%", | ||
| }, | ||
| }); |
43 changes: 43 additions & 0 deletions
43
dapps/pos-app/components/big-amount-input/BigAmountInput.types.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| import type { StyleProp, ViewStyle } from "react-native"; | ||
| import type { SupportedLocale, SymbolPosition } from "./utils/formatAmount"; | ||
|
|
||
| export type BigAmountInputProps = { | ||
| /** | ||
| * Current raw value (e.g., "24.00" for $24.00) | ||
| */ | ||
| value?: string; | ||
| /** | ||
| * Currency symbol to display (default: $) | ||
| */ | ||
| currency?: string; | ||
| /** | ||
| * Position of the currency symbol (default: left) | ||
| * "left" for "$10.00", "right" for "10.00€" | ||
| */ | ||
| symbolPosition?: SymbolPosition; | ||
| /** | ||
| * Locale for number formatting (en-US, fr-FR, de-DE, nl-NL) | ||
| */ | ||
| locale?: SupportedLocale; | ||
| /** | ||
| * Placeholder text when empty | ||
| */ | ||
| placeholder?: string; | ||
| /** | ||
| * Whether the input is focused (shows blinking cursor) | ||
| */ | ||
| isFocused?: boolean; | ||
| /** | ||
| * Whether cursor blinks when focused | ||
| * @default true | ||
ignaciosantise marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| */ | ||
| cursorBlinkEnabled?: boolean; | ||
| /** | ||
| * Test ID for testing | ||
| */ | ||
| testID?: string; | ||
| /** | ||
| * Style for the container | ||
| */ | ||
| style?: StyleProp<ViewStyle>; | ||
| }; | ||
110 changes: 110 additions & 0 deletions
110
dapps/pos-app/components/big-amount-input/components/AnimatedCharacter.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| import type { CharacterItem } from "../utils/getCharactersArray"; | ||
| import { useTheme } from "@/hooks/use-theme-color"; | ||
| import { memo, useEffect } from "react"; | ||
| import { StyleSheet } from "react-native"; | ||
| import Animated, { | ||
| Easing, | ||
| useAnimatedStyle, | ||
| useSharedValue, | ||
| withTiming, | ||
| } from "react-native-reanimated"; | ||
| import type { ExitAnimationsValues } from "react-native-reanimated"; | ||
|
|
||
| const easeOutExpo = Easing.out(Easing.exp); | ||
| const TIMING_CONFIG = { duration: 200, easing: easeOutExpo }; | ||
|
|
||
| const exitAnimation = (_values: ExitAnimationsValues) => { | ||
| "worklet"; | ||
| return { | ||
| animations: { | ||
| opacity: withTiming(0, TIMING_CONFIG), | ||
| transform: [{ translateY: withTiming(10, TIMING_CONFIG) }], | ||
| }, | ||
| initialValues: { | ||
| opacity: 1, | ||
| transform: [{ translateY: 0 }], | ||
| }, | ||
| }; | ||
| }; | ||
|
|
||
| type AnimatedCharacterProps = { | ||
| item: CharacterItem; | ||
| scale: number; | ||
| characterWidth: number; | ||
| itemHeight: number; | ||
| positionX: number; | ||
| isPlaceholder?: boolean; | ||
| }; | ||
|
|
||
| function AnimatedCharacterComponent({ | ||
| item, | ||
| scale, | ||
| characterWidth, | ||
| itemHeight, | ||
| positionX, | ||
| isPlaceholder = false, | ||
| }: AnimatedCharacterProps) { | ||
| const Theme = useTheme(); | ||
|
|
||
| const translateY = useSharedValue(10); | ||
| const opacity = useSharedValue(0); | ||
|
|
||
| useEffect(() => { | ||
| translateY.value = withTiming(0, TIMING_CONFIG); | ||
| opacity.value = withTiming(1, TIMING_CONFIG); | ||
| }, [translateY, opacity]); | ||
ignaciosantise marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Compensate for scale origin: RN scales from center, so we offset | ||
| // by half the width * (1 - scale) to simulate left-origin scaling | ||
| const scaleOffsetX = (characterWidth * (1 - scale)) / 2; | ||
|
|
||
| const animatedStyle = useAnimatedStyle( | ||
| () => ({ | ||
| opacity: opacity.value, | ||
| transform: [ | ||
| { | ||
| translateX: withTiming(positionX - scaleOffsetX, TIMING_CONFIG), | ||
| }, | ||
| { translateY: translateY.value }, | ||
| { scale: withTiming(scale, TIMING_CONFIG) }, | ||
| ], | ||
| }), | ||
| [positionX, scale, scaleOffsetX], | ||
| ); | ||
|
|
||
| const isPlaceholderChar = isPlaceholder || item.isPlaceholderDecimal; | ||
| const textColor = isPlaceholderChar | ||
| ? Theme["text-secondary"] | ||
| : Theme["text-primary"]; | ||
|
|
||
| return ( | ||
| <Animated.View exiting={exitAnimation}> | ||
| <Animated.View | ||
| style={[ | ||
| styles.container, | ||
| { width: characterWidth, height: itemHeight }, | ||
| animatedStyle, | ||
| ]} | ||
| > | ||
| <Animated.Text style={[styles.text, { color: textColor }]}> | ||
| {item.char} | ||
| </Animated.Text> | ||
| </Animated.View> | ||
| </Animated.View> | ||
| ); | ||
| } | ||
|
|
||
| export const AnimatedCharacter = memo(AnimatedCharacterComponent); | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| container: { | ||
| position: "absolute", | ||
| justifyContent: "center", | ||
| }, | ||
| text: { | ||
| fontFamily: "KH Teka", | ||
| fontSize: 64, | ||
| position: "absolute", | ||
ignaciosantise marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| textAlign: "center", | ||
| }, | ||
| }); | ||
107 changes: 107 additions & 0 deletions
107
dapps/pos-app/components/big-amount-input/components/AnimatedCursor.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,107 @@ | ||
| import { useTheme } from "@/hooks/use-theme-color"; | ||
| import { useEffect } from "react"; | ||
| import { StyleSheet } from "react-native"; | ||
| import Animated, { | ||
| cancelAnimation, | ||
| Easing, | ||
| useAnimatedStyle, | ||
| useSharedValue, | ||
| withRepeat, | ||
| withSequence, | ||
| withTiming, | ||
| } from "react-native-reanimated"; | ||
|
|
||
| const CURSOR_HEIGHT = 56; | ||
|
|
||
| type AnimatedCursorProps = { | ||
| isFocused: boolean; | ||
| cursorPosition: number; | ||
| scale: number; | ||
| blinkEnabled?: boolean; | ||
| containerHeight: number; | ||
| }; | ||
|
|
||
| export const AnimatedCursor = ({ | ||
| isFocused, | ||
| cursorPosition, | ||
| scale, | ||
| blinkEnabled = true, | ||
| containerHeight, | ||
| }: AnimatedCursorProps) => { | ||
| const Theme = useTheme(); | ||
| const opacity = useSharedValue(1); | ||
|
|
||
| useEffect(() => { | ||
| if (isFocused) { | ||
| if (blinkEnabled) { | ||
| opacity.value = withRepeat( | ||
| withSequence( | ||
| withTiming(1, { duration: 0 }), | ||
| withTiming(1, { duration: 500, easing: Easing.linear }), | ||
| withTiming(0, { duration: 0 }), | ||
| withTiming(0, { duration: 500, easing: Easing.linear }), | ||
| ), | ||
| -1, | ||
| false, | ||
| ); | ||
| } else { | ||
| opacity.value = 1; | ||
| } | ||
| } else { | ||
| opacity.value = withTiming(0, { duration: 100 }); | ||
| } | ||
|
|
||
| return () => { | ||
| cancelAnimation(opacity); | ||
| }; | ||
| }, [isFocused, opacity, blinkEnabled]); | ||
|
|
||
| // Scale height directly instead of transform to avoid position shift | ||
| const scaledHeight = CURSOR_HEIGHT * scale; | ||
| const topPosition = (containerHeight - scaledHeight) / 2; | ||
|
|
||
| const animatedStyle = useAnimatedStyle( | ||
| () => ({ | ||
| opacity: opacity.value, | ||
| height: withTiming(scaledHeight, { | ||
| duration: 200, | ||
| easing: Easing.out(Easing.ease), | ||
| }), | ||
| transform: [ | ||
| { | ||
| translateX: withTiming(cursorPosition, { | ||
| duration: 200, | ||
| easing: Easing.out(Easing.ease), | ||
| }), | ||
| }, | ||
| { | ||
| translateY: withTiming(topPosition, { | ||
| duration: 200, | ||
| easing: Easing.out(Easing.ease), | ||
| }), | ||
| }, | ||
| ], | ||
| }), | ||
| [cursorPosition, scaledHeight, topPosition], | ||
| ); | ||
|
|
||
| if (!isFocused) return null; | ||
ignaciosantise marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <Animated.View | ||
| style={[ | ||
| styles.cursor, | ||
| animatedStyle, | ||
| { backgroundColor: Theme["bg-accent-primary"] }, | ||
| ]} | ||
| /> | ||
| ); | ||
| }; | ||
|
|
||
| const styles = StyleSheet.create({ | ||
| cursor: { | ||
| position: "absolute", | ||
| width: 2, | ||
| borderRadius: 1, | ||
| }, | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.