Skip to content

Commit

Permalink
fix(connect-modal): prevent img layout thrashing
Browse files Browse the repository at this point in the history
  • Loading branch information
yyyyaaa committed Nov 24, 2023
1 parent 172cd2b commit 12492a4
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 49 deletions.
1 change: 1 addition & 0 deletions src/ui/animate-layout/animate-layout.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ export default function AnimateLayout(props: AnimateLayoutProps) {
style={{
backfaceVisibility: "hidden",
}}
data-part-id="animate-layout"
>
{props.children}
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,14 @@ export default function ConnectModalWalletButton(
<Box position="relative">
{/* When there is only logo, use normal image */}
<Show when={props.logo && !props.btmLogo}>
<img
alt={props.name}
src={props.logo}
className={fullWidthHeight}
<Box
as="img"
attributes={{
alt: props.name,
src: props.logo,
}}
width={props.variant === "square" ? "$16" : "$12"}
height={props.variant === "square" ? "$16" : "$12"}
/>
</Show>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,11 @@ export const walletList = style({
},
"&[data-has-list-wallets='true']": {
paddingBottom: themeVars.space[8],
}
},
},
});

export const squareWallets = style({
display: "grid",
columnGap: themeVars.space[5],
gridTemplateColumns: "repeat(2, minmax(0, 1fr))",
marginBottom: themeVars.space[5],
Expand Down
91 changes: 48 additions & 43 deletions src/ui/connect-modal-wallet-list/connect-modal-wallet-list.lite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import anime from "animejs";
import type { AnimeInstance } from "animejs";
import clx from "clsx";
import Box from "../box";
import FadeIn from "../fade-in";
import WalletButton from "../connect-modal-wallet-button";
import {
walletList,
Expand Down Expand Up @@ -48,6 +49,11 @@ export default function ConnectModalWalletList(
getListShapeWallets() {
return props.wallets.filter((w) => w.shape === "list");
},
showSquareShapeWallets() {
return props.wallets
.slice(0, 2)
.every((wallet) => wallet.shape === "square");
},
});

onMount(() => {
Expand Down Expand Up @@ -124,52 +130,51 @@ export default function ConnectModalWalletList(
className={walletList}
data-has-list-wallets={state.getListShapeWallets().length > 0}
>
<Show
when={props.wallets
.slice(0, 2)
.every((wallet) => wallet.shape === "square")}
>
<div className={squareWallets}>
{/* First 2 wallets are square */}
<For each={props.wallets.slice(0, 2)}>
{(wallet, index) => (
<WalletButton
key={`${wallet.name}-${index}`}
variant="square"
name={wallet.prettyName ?? wallet.name}
logo={wallet.logo}
subLogo={wallet.subLogo}
btmLogo={wallet.btmLogo}
onClick={state.onWalletItemClickAsync(async () =>
props.onWalletItemClick?.(wallet.originalWallet)
)}
/>
)}
</For>
</div>
<Show when={state.showSquareShapeWallets()}>
<FadeIn isVisible={state.showSquareShapeWallets()}>
<Box display={"grid"} className={squareWallets}>
{/* First 2 wallets are square */}
<For each={props.wallets.slice(0, 2)}>
{(wallet, index) => (
<WalletButton
key={`${wallet.name}-${index}`}
variant="square"
name={wallet.prettyName ?? wallet.name}
logo={wallet.logo}
subLogo={wallet.subLogo}
btmLogo={wallet.btmLogo}
onClick={state.onWalletItemClickAsync(async () =>
props.onWalletItemClick?.(wallet.originalWallet)
)}
/>
)}
</For>
</Box>
</FadeIn>
</Show>

<Box
display={state.getListShapeWallets().length === 0 ? "none" : "grid"}
className={listWallets}
>
<For each={state.getListShapeWallets()}>
{(wallet, index) => (
<WalletButton
key={`${wallet.name}-${index}`}
variant="list"
name={wallet.prettyName ?? wallet.name}
logo={wallet.logo}
badge={wallet.badge}
subLogo={wallet.subLogo}
btmLogo={wallet.btmLogo}
onClick={state.onWalletItemClickAsync(async () =>
props.onWalletItemClick?.(wallet.originalWallet)
<Show when={state.getListShapeWallets().length > 0}>
<FadeIn isVisible={state.getListShapeWallets().length > 0}>
<Box display={"grid"} className={listWallets}>
<For each={state.getListShapeWallets()}>
{(wallet, index) => (
<WalletButton
key={`${wallet.name}-${index}`}
variant="list"
name={wallet.prettyName ?? wallet.name}
logo={wallet.logo}
badge={wallet.badge}
subLogo={wallet.subLogo}
btmLogo={wallet.btmLogo}
onClick={state.onWalletItemClickAsync(async () =>
props.onWalletItemClick?.(wallet.originalWallet)
)}
/>
)}
/>
)}
</For>
</Box>
</For>
</Box>
</FadeIn>
</Show>
</div>

<div ref={shadowRef} className={bottomShadow[state.theme]} />
Expand Down

0 comments on commit 12492a4

Please sign in to comment.