Skip to content

Commit a76c49d

Browse files
authored
feat: add logic to render AppKit Core in fullscreen on mobile environments (#5090)
1 parent b5492b1 commit a76c49d

File tree

20 files changed

+330
-22
lines changed

20 files changed

+330
-22
lines changed

.changeset/blue-lizards-exist.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
'@reown/appkit-controllers': patch
3+
'@reown/appkit-scaffold-ui': patch
4+
'@reown/appkit': patch
5+
---
6+
7+
Add a param to AppKit to make it possible to render AppKit Core in fullscreen on mobile

apps/laboratory/src/constants/appKitConfigs.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -311,7 +311,8 @@ export const appKitConfigs = {
311311
'multichain-no-adapters': {
312312
...commonAppKitConfig,
313313
adapters: [],
314-
networks: ConstantsUtil.AllNetworks
314+
networks: ConstantsUtil.AllNetworks,
315+
enableMobileFullScreen: true
315316
},
316317
'multichain-wagmi-solana': {
317318
...commonAppKitConfig,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
export const PACKAGE_VERSION = '1.8.6'
1+
export const PACKAGE_VERSION = '1.8.7'

packages/appkit/src/client/appkit-base-client.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,7 @@ export abstract class AppKitBaseClient {
418418
OptionsController.setEIP6963Enabled(options.enableEIP6963 !== false)
419419
OptionsController.setEnableNetworkSwitch(options.enableNetworkSwitch !== false)
420420
OptionsController.setEnableReconnect(options.enableReconnect !== false)
421+
OptionsController.setEnableMobileFullScreen(options.enableMobileFullScreen === true)
421422

422423
OptionsController.setEnableAuthLogger(options.enableAuthLogger !== false)
423424
OptionsController.setCustomRpcUrls(options.customRpcUrls)

packages/controllers/src/controllers/OptionsController.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { subscribeKey as subKey } from 'valtio/vanilla/utils'
44
import type { CaipNetworkId, CustomRpcUrl } from '@reown/appkit-common'
55

66
import { ConstantsUtil } from '../utils/ConstantsUtil.js'
7+
import { CoreHelperUtil } from '../utils/CoreHelperUtil.js'
78
import { OptionsUtil } from '../utils/OptionsUtil.js'
89
import type { SIWXConfig } from '../utils/SIWXUtil.js'
910
import type {
@@ -194,6 +195,11 @@ export interface OptionsControllerStatePublic {
194195
* @default true
195196
*/
196197
enableNetworkSwitch?: boolean
198+
/**
199+
* Render the modal as full height on mobile web browsers.
200+
* @default false
201+
*/
202+
enableMobileFullScreen?: boolean
197203
}
198204

199205
export interface OptionsControllerStateInternal {
@@ -216,7 +222,8 @@ const state = proxy<OptionsControllerState>({
216222
defaultAccountTypes: ConstantsUtil.DEFAULT_ACCOUNT_TYPES,
217223
enableNetworkSwitch: true,
218224
experimental_preferUniversalLinks: false,
219-
remoteFeatures: {}
225+
remoteFeatures: {},
226+
enableMobileFullScreen: false
220227
})
221228

222229
// -- Controller ---------------------------------------- //
@@ -415,6 +422,12 @@ export const OptionsController = {
415422
state.enableNetworkSwitch = enableNetworkSwitch
416423
},
417424

425+
setEnableMobileFullScreen(
426+
enableMobileFullScreen: OptionsControllerState['enableMobileFullScreen']
427+
) {
428+
state.enableMobileFullScreen = CoreHelperUtil.isMobile() && enableMobileFullScreen
429+
},
430+
418431
setEnableReconnect(enableReconnect: OptionsControllerState['enableReconnect']) {
419432
state.enableReconnect = enableReconnect
420433
},

packages/controllers/tests/controllers/OptionsController.test.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { beforeEach, describe, expect, it, vi } from 'vitest'
22

33
import { OptionsController } from '../../exports/index.js'
44
import { ConstantsUtil } from '../../src/utils/ConstantsUtil.js'
5+
import { CoreHelperUtil } from '../../src/utils/CoreHelperUtil.js'
56
import { OptionsUtil } from '../../src/utils/OptionsUtil.js'
67
import type { RemoteFeatures, SocialProvider } from '../../src/utils/TypeUtil.js'
78

@@ -32,7 +33,8 @@ describe('OptionsController', () => {
3233
solana: 'eoa'
3334
},
3435
enableNetworkSwitch: true,
35-
experimental_preferUniversalLinks: false
36+
experimental_preferUniversalLinks: false,
37+
enableMobileFullScreen: false
3638
})
3739
})
3840

@@ -107,4 +109,18 @@ describe('OptionsController', () => {
107109
OptionsController.setSIWX({ signOutOnDisconnect: false } as any)
108110
expect(OptionsController.state.siwx!.signOutOnDisconnect).toEqual(false)
109111
})
112+
113+
it('should set enableMobileFullScreen to false when not on mobile', () => {
114+
const spy = vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(false)
115+
OptionsController.setEnableMobileFullScreen(true)
116+
expect(OptionsController.state.enableMobileFullScreen).toBe(false)
117+
spy.mockRestore()
118+
})
119+
120+
it('should set enableMobileFullScreen to true when on mobile', () => {
121+
const spy = vi.spyOn(CoreHelperUtil, 'isMobile').mockReturnValue(true)
122+
OptionsController.setEnableMobileFullScreen(true)
123+
expect(OptionsController.state.enableMobileFullScreen).toBe(true)
124+
spy.mockRestore()
125+
})
110126
})

packages/scaffold-ui/src/modal/w3m-modal/index.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ export class W3mModalBase extends LitElement {
6969

7070
@state() private padding = vars.spacing[1]
7171

72+
@state() private mobileFullScreen = OptionsController.state.enableMobileFullScreen
73+
7274
public constructor() {
7375
super()
7476
this.initializeTheming()
@@ -97,6 +99,10 @@ export class W3mModalBase extends LitElement {
9799
public override firstUpdated() {
98100
this.dataset['border'] = HelpersUtil.hasFooter() ? 'true' : 'false'
99101

102+
if (this.mobileFullScreen) {
103+
this.setAttribute('data-mobile-fullscreen', 'true')
104+
}
105+
100106
if (this.caipAddress) {
101107
if (this.enableEmbedded) {
102108
ModalController.close()
@@ -125,10 +131,6 @@ export class W3mModalBase extends LitElement {
125131
// -- Render -------------------------------------------- //
126132
public override render() {
127133
this.style.setProperty('--local-modal-padding', this.padding)
128-
this.style.setProperty(
129-
'--local-border-bottom-mobile-radius',
130-
this.enableEmbedded ? `clamp(0px, ${vars.borderRadius['8']}, 44px)` : '0px'
131-
)
132134

133135
if (this.enableEmbedded) {
134136
return html`${this.contentTemplate()}
@@ -165,6 +167,9 @@ export class W3mModalBase extends LitElement {
165167

166168
private async onOverlayClick(event: PointerEvent) {
167169
if (event.target === event.currentTarget) {
170+
if (this.mobileFullScreen) {
171+
return
172+
}
168173
await this.handleClose()
169174
}
170175
}

packages/scaffold-ui/src/modal/w3m-modal/styles.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ export default css`
7474
will-change: box-shadow;
7575
}
7676
77+
:host([data-mobile-fullscreen='true']) wui-card::before {
78+
border-radius: 0px;
79+
}
80+
7781
:host([data-border='true']) wui-card::before {
7882
box-shadow: inset 0px 0px 0px 4px ${({ tokens }) => tokens.theme.foregroundSecondary};
7983
}
@@ -132,17 +136,37 @@ export default css`
132136
}
133137
134138
@media (max-width: 430px) {
135-
wui-flex {
139+
:host([data-mobile-fullscreen='true']) {
140+
height: 100dvh;
141+
}
142+
:host([data-mobile-fullscreen='true']) wui-flex {
143+
align-items: stretch;
144+
}
145+
:host([data-mobile-fullscreen='true']) wui-card {
146+
max-width: 100%;
147+
height: 100%;
148+
border-radius: 0;
149+
border: none;
150+
}
151+
:host(:not([data-mobile-fullscreen='true'])) wui-flex {
136152
align-items: flex-end;
137153
}
138154
139-
wui-card {
155+
:host(:not([data-mobile-fullscreen='true'])) wui-card {
140156
max-width: 100%;
141-
border-bottom-left-radius: var(--local-border-bottom-mobile-radius);
142-
border-bottom-right-radius: var(--local-border-bottom-mobile-radius);
143157
border-bottom: none;
144158
}
145159
160+
:host(:not([data-mobile-fullscreen='true'])) wui-card[data-embedded='true'] {
161+
border-bottom-left-radius: clamp(0px, var(--apkt-borderRadius-8), 44px);
162+
border-bottom-right-radius: clamp(0px, var(--apkt-borderRadius-8), 44px);
163+
}
164+
165+
:host(:not([data-mobile-fullscreen='true'])) wui-card:not([data-embedded='true']) {
166+
border-bottom-left-radius: 0px;
167+
border-bottom-right-radius: 0px;
168+
}
169+
146170
wui-card[shake='true'] {
147171
animation: w3m-shake 0.5s ${({ easings }) => easings['ease-out-power-2']};
148172
}

packages/scaffold-ui/src/partials/w3m-all-wallets-list/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import {
66
ApiController,
77
ConnectorController,
88
CoreHelperUtil,
9+
OptionsController,
910
type WcWallet
1011
} from '@reown/appkit-controllers'
1112
import { customElement } from '@reown/appkit-ui'
@@ -41,6 +42,8 @@ export class W3mAllWalletsList extends LitElement {
4142

4243
@state() private badge?: 'certified' | undefined
4344

45+
@state() private mobileFullScreen = OptionsController.state.enableMobileFullScreen
46+
4447
public constructor() {
4548
super()
4649
this.unsubscribe.push(
@@ -65,6 +68,10 @@ export class W3mAllWalletsList extends LitElement {
6568

6669
// -- Render -------------------------------------------- //
6770
public override render() {
71+
if (this.mobileFullScreen) {
72+
this.setAttribute('data-mobile-fullscreen', 'true')
73+
}
74+
6875
return html`
6976
<wui-grid
7077
data-scroll=${!this.loading}

packages/scaffold-ui/src/partials/w3m-all-wallets-list/styles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ export default css`
99
grid-template-columns: repeat(auto-fill, 104px);
1010
}
1111
12+
:host([data-mobile-fullscreen='true']) wui-grid {
13+
max-height: none;
14+
}
15+
1216
@media (max-width: 350px) {
1317
wui-grid {
1418
grid-template-columns: repeat(2, 1fr);

0 commit comments

Comments
 (0)