Skip to content

Commit

Permalink
Merge branch 'fix/tabs'
Browse files Browse the repository at this point in the history
  • Loading branch information
ickg5 committed Sep 8, 2021
2 parents ee4246c + 520a3ee commit 401e87d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 14 deletions.
23 changes: 11 additions & 12 deletions packages/core/src/tabs/tabs-header.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ScrollView, View } from "@tarojs/components"
import { nextTick, offWindowResize, onWindowResize, useReady } from "@tarojs/taro"
import { offWindowResize, onWindowResize, useReady } from "@tarojs/taro"
import classNames from "classnames"
import * as _ from "lodash"
import * as React from "react"
Expand Down Expand Up @@ -35,9 +35,10 @@ export default function TabsHeader() {
const [navOffset, setNavOffset] = useState<NavOffset>({})
const [tabOffsets, setTabOffsets] = useState<TabOffset[]>([])

const activeIndex = useMemo(() => {
return _.find(tabObjects, (tab) => tab.key === activeKey)?.index ?? -1
}, [tabObjects, activeKey])
const activeIndex = useMemo(
() => _.find(tabObjects, (tab) => tab.key === activeKey)?.index ?? -1,
[tabObjects, activeKey],
)

const activeOffset = useMemo(() => {
if (_.isEmpty(tabOffsets) || activeIndex === -1) {
Expand All @@ -60,14 +61,12 @@ export default function TabsHeader() {
}, [navOffset, activeOffset])

const resize = useCallback(() => {
nextTick(() => {
Promise.all([
getBoundingClientRect(navRef),
getBoundingClientRects(navRef, ` .${prefixClassname("tabs__tab")}`),
]).then(([navRect, tabRects]) => {
setNavOffset(navRect)
setTabOffsets(tabRects)
})
Promise.all([
getBoundingClientRect(navRef),
getBoundingClientRects(navRef, ` .${prefixClassname("tabs__tab")}`),
]).then(([navRect, tabRects]) => {
setNavOffset(navRect)
setTabOffsets(tabRects)
})
}, [])

Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/tabs/tabs.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { View } from "@tarojs/components"
import classNames from "classnames"
import * as React from "react"
import { Children, ReactElement, ReactNode, useMemo, useRef } from "react"
import { Children, isValidElement, ReactElement, ReactNode, useMemo, useRef } from "react"
import Sticky from "../sticky"
import { prefixClassname } from "../styles"
import TabPane from "./tab-pane"
Expand All @@ -16,7 +16,7 @@ function useTabObjects(children: ReactNode) {

let index = 0
Children.forEach(children, (node: ReactNode, i: number) => {
if (!React.isValidElement(node)) {
if (!isValidElement(node)) {
return node
}
const element = node as ReactElement
Expand Down

0 comments on commit 401e87d

Please sign in to comment.