Skip to content

Commit

Permalink
fix: mobile onload callbacks (#177)
Browse files Browse the repository at this point in the history
  • Loading branch information
flops authored Aug 22, 2024
1 parent 2daea97 commit da6a713
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/DashKitView/DashKitView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ type DashKitViewProps = DashKitProps & {
function DashKitView() {
const context = React.useContext(DashKitContext);
const {registerManager, forwardedMetaRef} = context;

return (
<div className={b({theme: registerManager.settings.theme})}>
{registerManager.settings.isMobile ? (
Expand Down
32 changes: 32 additions & 0 deletions src/components/MobileLayout/MobileLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,36 @@ export default class MobileLayout extends React.PureComponent {
}
};

onMountChange = (isMounted) => {
if (isMounted) {
this._inited = true;

this.context.onItemMountChange?.(this.props.item, {
isAsync: this._isAsyncItem,
isMounted: isMounted,
});

if (!this._isAsyncItem) {
this.context.onItemRender?.(this.props.item);
}
} else {
this.context.onItemMountChange?.(this.props.item, {
isAsync: this._isAsyncItem,
isMounted: isMounted,
});
}
};

onBeforeLoad = () => {
this._isAsyncItem = true;

return this.onLoad;
};

onLoad = () => {
this.context.onItemRender?.(this.props.item);
};

render() {
const {config, layout} = this.context;

Expand Down Expand Up @@ -75,6 +105,8 @@ export default class MobileLayout extends React.PureComponent {
forwardedPluginRef={(pluginRef) => {
this.pluginsRefs[index] = pluginRef;
}}
onMountChange={this.onMountChange}
onBeforeLoad={this.onBeforeLoad}
/>
</div>
);
Expand Down
6 changes: 3 additions & 3 deletions src/typings/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ export type SetConfigItem = ConfigItem | AddConfigItem;

export type SetItemOptions = {
excludeIds?: string[];
};

export type SetNewItemOptions = SetItemOptions & {
updateLayout?: ConfigLayout[];
};

export type SetNewItemOptions = SetItemOptions;

export interface DashkitGroupRenderProps {
config: Config;
editMode: boolean;
Expand Down

0 comments on commit da6a713

Please sign in to comment.