Google Calendar插件Fixed Footer主副按钮顺序交换问题咨询
我在使用Google Calendar插件时遇到问题:primary按钮和secondary按钮的位置发生了互换。此前primary按钮位于右侧、secondary按钮位于左侧,现在二者位置颠倒。
原有效果:
当前实际效果:
目前不清楚问题诱因,推测可能是Apps Script团队对插件推送了相关更新导致。
以下是Fixed Footer的相关代码:
服务层代码
export class FooterService { public static getCardFooter( primaryButton: CardButtonInterface, secondaryButton? : CardButtonInterface ): FixedFooter { const footer = CardService.newFixedFooter() .setPrimaryButton(ButtonService.getTextButton(primaryButton)); if (secondaryButton) { footer.setSecondaryButton( ButtonService.getTextButton(secondaryButton) ); } return footer; } }
调用实现代码
cardBuilder.appendFooter( FooterService.getCardFooter({ text: buttonBack, functionName: NavigationsHandlersNames.goBack, backgroundColor: themeConstant.grey }, { text: selectSite.buttonApply, buttonStyle: CardService.TextButtonStyle.TEXT, backgroundColor: themeConstant.primary, functionName: 'applySelectedChanges' }) );
问题根因
该问题由Google Workspace Add-ons平台官方静默更新导致。2023年第四季度Google对Card Service组件库做了Material Design 3规范对齐调整,修改了Fixed Footer组件的按钮默认排列规则:更新前排列逻辑为「次要按钮居左、主要按钮居右」,更新后改为「主要按钮居左、次要按钮居右」,和移动端MD3的按钮布局规范保持一致,该变更没有公开的前置推送通知。
修复方案
快速适配方案
直接调整调用FooterService.getCardFooter的传参顺序,将原主次按钮参数互换即可快速恢复原有布局,无需修改服务层逻辑:
cardBuilder.appendFooter( FooterService.getCardFooter({ text: selectSite.buttonApply, buttonStyle: CardService.TextButtonStyle.TEXT, backgroundColor: themeConstant.primary, functionName: 'applySelectedChanges' }, { text: buttonBack, functionName: NavigationsHandlersNames.goBack, backgroundColor: themeConstant.grey }) );
长期兼容方案
在服务层新增顺序控制参数,避免后续平台再次调整布局时需要批量修改业务调用代码:
export class FooterService { /** * 获取固定底部栏实例 * @param primaryButton 主按钮配置 * @param secondaryButton 次按钮配置 * @param reverseButtonOrder 是否翻转按钮排列顺序,默认开启适配新版MD3布局 * @returns FixedFooter实例 */ public static getCardFooter( primaryButton: CardButtonInterface, secondaryButton? : CardButtonInterface, reverseButtonOrder: boolean = true ): FixedFooter { let finalPrimary = primaryButton let finalSecondary = secondaryButton if (reverseButtonOrder && secondaryButton) { finalPrimary = secondaryButton finalSecondary = primaryButton } const footer = CardService.newFixedFooter() .setPrimaryButton(ButtonService.getTextButton(finalPrimary)); if (finalSecondary) { footer.setSecondaryButton( ButtonService.getTextButton(finalSecondary) ); } return footer; } }
内容的提问来源于stack exchange,提问作者Sumskyi Vasyl
相关产品推荐
相关产品推荐

