Skip to content

Commit

Permalink
fix: swiper onlayout
Browse files Browse the repository at this point in the history
  • Loading branch information
linjinze999 committed May 11, 2024
1 parent 80d63e3 commit 91b5822
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/hippy_ui_react/src/components/Swiper/PropsType.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ReactNode } from 'react';
import { ViewStyle, GenericStyleProp } from '@hippy/react';
import { ViewStyle, GenericStyleProp, LayoutEvent } from '@hippy/react';
import { IndicatorProps } from '../Indicator/PropsType';

export interface ScrollEvent {
Expand All @@ -21,6 +21,8 @@ export interface SwiperProps {
children: ReactNode[];
/** 页码改变时会触发 change 事件 */
onChange?: (index: number) => void;
/** 布局回调事件 */
onLayout?: (layoutEvent: LayoutEvent) => void;
/** 开始拖拽时触发 事件 */
onScrollBeginDrag?: (event?: ScrollEvent) => void;
/** 结束拖拽时触发 事件 */
Expand Down
3 changes: 2 additions & 1 deletion packages/hippy_ui_react/src/components/Swiper/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ export class Swiper extends Component<SwiperProps, SwiperState> {
};

render() {
const { style, scrollEnabled, autoScrollWidth, onScrollBeginDrag, onScrollEndDrag } = this.props;
const { style, scrollEnabled, autoScrollWidth, onScrollBeginDrag, onScrollEndDrag, onLayout } = this.props;
return (
<>
<ScrollView
Expand All @@ -435,6 +435,7 @@ export class Swiper extends Component<SwiperProps, SwiperState> {
this.refWrap = c;
}}
onLayout={(e) => {
onLayout?.(e);
this.wrapWidth = e.layout.width;
}}
horizontal={true}
Expand Down

0 comments on commit 91b5822

Please sign in to comment.