Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Tabs scroll offset in ssr when defaultActiveTab is greater than 0 #175

Merged
merged 4 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ output_resource/
.history
*.func-info.json
*.mixin-info.json
.npmrc

# Emacs
*~
Expand Down
10 changes: 5 additions & 5 deletions packages/arcodesign/components/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
export { default as Tabs } from './tabs';
export { default as Sticky } from './sticky';
export { default as LoadMore } from './load-more';
export { default as Cell } from './cell';
export { default as Portal } from './portal';
export { default as Toast } from './toast';
export { default as ActionSheet } from './action-sheet';
export { default as Avatar } from './avatar';
export { default as Badge } from './badge';
export { default as Button } from './button';
export { default as Carousel } from './carousel';
export { default as Cell } from './cell';
export { default as Checkbox } from './checkbox';
export { default as CircleProgress } from './circle-progress';
export { default as Collapse } from './collapse';
Expand All @@ -26,6 +27,7 @@ export { default as ImagePreview } from './image-preview';
export { default as IndexBar } from './index-bar';
export { default as Input } from './input';
export { default as Keyboard } from './keyboard';
export { default as LoadMore } from './load-more';
export { default as Loading } from './loading';
export { default as Masking } from './masking';
export { default as NavBar } from './nav-bar';
Expand All @@ -37,14 +39,13 @@ export { default as PickerView } from './picker-view';
export { default as Popover } from './popover';
export { default as Popup } from './popup';
export { default as PopupSwiper } from './popup-swiper';
export { default as Portal } from './portal';
export { default as Progress } from './progress';
export { default as PullRefresh } from './pull-refresh';
export { default as Radio } from './radio';
export { default as Rate } from './rate';
export { default as SearchBar } from './search-bar';
export { default as Skeleton } from './skeleton';
export { default as ShowMonitor } from './show-monitor';
export { default as Skeleton } from './skeleton';
export { default as Slider } from './slider';
export { default as Stepper } from './stepper';
export { default as Steps } from './steps';
Expand All @@ -54,5 +55,4 @@ export { default as Switch } from './switch';
export { default as TabBar } from './tab-bar';
export { default as Tag } from './tag';
export { default as Textarea } from './textarea';
export { default as Toast } from './toast';
export { default as Transition } from './transition';
10 changes: 5 additions & 5 deletions packages/arcodesign/components/style.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import '../style/public.less';
import './tabs/style';
import './sticky/style';
import './load-more/style';
import './cell/style';
import './portal/style';
import './toast/style';
import './action-sheet/style';
import './avatar/style';
import './badge/style';
import './button/style';
import './carousel/style';
import './cell/style';
import './checkbox/style';
import './circle-progress/style';
import './collapse/style';
Expand All @@ -27,6 +28,7 @@ import './image-preview/style';
import './index-bar/style';
import './input/style';
import './keyboard/style';
import './load-more/style';
import './loading/style';
import './masking/style';
import './nav-bar/style';
Expand All @@ -38,14 +40,13 @@ import './picker-view/style';
import './popover/style';
import './popup/style';
import './popup-swiper/style';
import './portal/style';
import './progress/style';
import './pull-refresh/style';
import './radio/style';
import './rate/style';
import './search-bar/style';
import './skeleton/style';
import './show-monitor/style';
import './skeleton/style';
import './slider/style';
import './stepper/style';
import './steps/style';
Expand All @@ -55,5 +56,4 @@ import './switch/style';
import './tab-bar/style';
import './tag/style';
import './textarea/style';
import './toast/style';
import './transition/style';
15 changes: 10 additions & 5 deletions packages/arcodesign/components/tabs/tab-pane.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import React, {
useMemo,
} from 'react';
import lodashThrottle from 'lodash.throttle';
import { cls, scrollWithAnimation, getScrollContainerRect } from '@arco-design/mobile-utils';
import { cls, scrollWithAnimation, getScrollContainerRect, isSSR } from '@arco-design/mobile-utils';
import { getStyleWithVendor } from '../_helpers';
import { TabPaneProps, TabPaneRef } from './type';

Expand Down Expand Up @@ -220,19 +220,24 @@ const TabPane = forwardRef((props: TabPaneProps, ref: Ref<TabPaneRef>) => {
return commonStyle;
}
const translateStr = translateZ ? ' translateZ(0)' : '';
const translatePercentInSSR = `${
(panes.length ? 100 / panes.length : 0) * activeIndex * rtlRatio * -1
}%`;
const verticalTranslate = `${distance - wrapWidth * activeIndex * rtlRatio}px`;
const horizontalTranslate = `${distance - wrapHeight * activeIndex}px`;
const sizeStyle =
tabDirection === 'vertical'
? {
width: `${100 * panes.length}%`,
transform: `translateX(${
distance - wrapWidth * activeIndex * rtlRatio
}px)${translateStr}`,
isSSR() ? translatePercentInSSR : verticalTranslate
})${translateStr}`,
}
: {
height: `${100 * panes.length}%`,
transform: `translateY(${
distance - wrapHeight * activeIndex
}px)${translateStr}`,
isSSR() ? translatePercentInSSR : horizontalTranslate
})${translateStr}`,
};
const heightStyle =
currentPaneHeight && currentPaneHeight !== 'auto'
Expand Down
4 changes: 4 additions & 0 deletions packages/common-widgets/utils/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,7 @@ export function isIPhoneX() {
return false;
}
}

export function isSSR() {
return typeof window === 'undefined';
}