Skip to content

Commit

Permalink
fix(mobile): fix incorrect burndown amount and budget scroll issue
Browse files Browse the repository at this point in the history
  • Loading branch information
bkdev98 committed Sep 22, 2024
1 parent c6d4d76 commit 25413cf
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
22 changes: 19 additions & 3 deletions apps/mobile/app/(app)/(tabs)/budgets.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,21 @@ export default function BudgetsScreen() {
}
})

const headerStyle = useAnimatedStyle(() => {
return {
transform: [
{
translateY: interpolate(
headerAnimation.value,
[0, chartHeight * 1.5, chartHeight * 1.7],
[0, 0, -chartHeight],
Extrapolation.EXTEND,
),
},
],
}
})

const summaryStyle = useAnimatedStyle(() => {
const extraSectionHeaderSpacing = spacing * 2
return {
Expand Down Expand Up @@ -175,7 +190,7 @@ export default function BudgetsScreen() {
const chartData = map(
groupBy(
transactions.filter((i) => !!i.budgetId),
(t) => t.date,
(transaction) => dayjsExtended(transaction.date).format('YYYY-MM-DD'),
),
(transactions, key) => ({
day: new Date(key).getDate(),
Expand All @@ -199,8 +214,9 @@ export default function BudgetsScreen() {

return (
<View className="flex-1 bg-background">
<View
<Animated.View
className="absolute z-50 w-full"
style={headerStyle}
onLayout={(ev) => {
if (headerHeight.value === ev.nativeEvent.layout.height) {
return
Expand All @@ -226,7 +242,7 @@ export default function BudgetsScreen() {
data={chartData}
/>
</Animated.View>
</View>
</Animated.View>
<AnimatedSectionList
onScroll={onScroll}
showsVerticalScrollIndicator={false}
Expand Down
26 changes: 22 additions & 4 deletions apps/mobile/app/(app)/budget/[budgetId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,21 @@ export default function BudgetDetailScreen() {
}
})

const headerStyle = useAnimatedStyle(() => {
return {
transform: [
{
translateY: interpolate(
headerAnimation.value,
[0, chartHeight * 1.5, chartHeight * 1.7],
[0, 0, -chartHeight],
Extrapolation.EXTEND,
),
},
],
}
})

const summaryStyle = useAnimatedStyle(() => {
const extraSectionHeaderSpacing = spacing * 2
return {
Expand Down Expand Up @@ -190,7 +205,9 @@ export default function BudgetDetailScreen() {
}

const chartData = map(
groupBy(transactions, (t) => t.date),
groupBy(transactions, (transaction) =>
dayjsExtended(transaction.date).format('YYYY-MM-DD'),
),
(transactions, key) => ({
day: new Date(key).getDate(),
amount: transactions.reduce((acc, t) => acc - t.amountInVnd, 0),
Expand All @@ -204,8 +221,9 @@ export default function BudgetDetailScreen() {
index={currentPeriodIndex}
onChange={setCurrentPeriodIndex}
/>
<View
className="absolute top-12 z-50 w-full"
<Animated.View
className="absolute top-12 z-10 w-full"
style={headerStyle}
onLayout={(ev) => {
if (headerHeight.value === ev.nativeEvent.layout.height) {
return
Expand Down Expand Up @@ -237,7 +255,7 @@ export default function BudgetDetailScreen() {
}
/>
</Animated.View>
</View>
</Animated.View>
<AnimatedSectionList
onScroll={onScroll}
showsVerticalScrollIndicator={false}
Expand Down
8 changes: 4 additions & 4 deletions apps/mobile/components/budget/budget-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ export const BudgetItem: FC<BudgetItemProps> = ({ budget }) => {
>
<Pressable className="mx-6 mt-1 mb-3 justify-between gap-4 rounded-lg border border-border p-4">
<View className="flex-row items-center justify-between gap-6">
<View className="flex-1 gap-3">
<View className="flex-1 gap-2">
<Text
numberOfLines={1}
className="line-clamp-1 flex-1 font-semiBold text-xl"
className="line-clamp-1 flex-1 font-semiBold text-lg"
>
{budget.name}
</Text>
Expand Down Expand Up @@ -90,7 +90,7 @@ export const BudgetItem: FC<BudgetItemProps> = ({ budget }) => {
<AmountFormat
amount={remainingAmount?.toNumber() ?? 0}
displayNegativeSign
className="text-xl"
className="text-lg"
currency={budget.preferredCurrency}
/>
<Text
Expand All @@ -104,7 +104,7 @@ export const BudgetItem: FC<BudgetItemProps> = ({ budget }) => {
<AmountFormat
amount={remainingAmountPerDays?.toNumber() ?? 0}
displayNegativeSign
className="text-xl"
className="text-lg"
currency={budget.preferredCurrency}
/>
<Text
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ export function BurndownChart({
})

useEffect(() => {
if (isFirstPressActive) {
if (firstTouch.x) {
Haptics.selectionAsync().catch(() => null)
}
}, [isFirstPressActive])
}, [firstTouch.x])

return (
<View className="min-h-[200px] w-full rounded-lg bg-muted">
Expand Down

0 comments on commit 25413cf

Please sign in to comment.