@bifrostui/react 2.0.0-alpha.14 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,4 +1,4 @@
1
1
  import React from 'react';
2
2
  import { DatePickerProps } from './DatePicker.types';
3
- declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "value" | "defaultValue" | "onChange" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
3
+ declare const DatePicker: React.ForwardRefExoticComponent<Omit<DatePickerProps<"div", Omit<import("../Picker").PickerProps<"div", import("..").DrawerProps>, "defaultValue" | "onChange" | "value" | "onClose" | "onConfirm">>, "ref"> & React.RefAttributes<HTMLDivElement>>;
4
4
  export default DatePicker;
@@ -12,5 +12,5 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
12
12
  keepMounted?: boolean;
13
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
14
  ref?: React.Ref<HTMLDivElement>;
15
- }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, keyof import("@bifrostui/types").ICommonProps | "open" | "container" | "disablePortal" | "onClose" | "hideBackdrop" | "BackdropProps" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  export default Modal;
@@ -126,8 +126,8 @@ const Tabs = (props) => {
126
126
  });
127
127
  const handleClick = (0, import_utils.useEventCallback)(
128
128
  (e, item) => {
129
- const { index, disabled: isDisabled = false } = item;
130
- if (isDisabled || [void 0, null].includes(index))
129
+ const { index, disabled = false } = item;
130
+ if (disabled || [void 0, null].includes(index))
131
131
  return;
132
132
  if (index !== currentValue) {
133
133
  triggerValueChange(e, index);
@@ -164,33 +164,47 @@ const Tabs = (props) => {
164
164
  }
165
165
  }));
166
166
  }, [scrollViewId, registrationVersion, registeredTabValues.length]);
167
+ const centerActiveTab = (0, import_utils.useEventCallback)(() => __async(void 0, null, function* () {
168
+ if (!currentValue || registeredTabValues.length === 0) {
169
+ return;
170
+ }
171
+ const { scrollView, scrollFields, wrapper, currentTab } = yield (0, import_queryBatch.batchQueryForScroll)({
172
+ scrollViewId,
173
+ wrapperId,
174
+ currentTabValue: currentValue
175
+ });
176
+ if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
177
+ return;
178
+ }
179
+ const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
180
+ const tabWidth = currentTab.width;
181
+ const containerViewWidth = scrollView.width;
182
+ const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
183
+ const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
184
+ const maxScrollDistance = currentScrollWidth - containerViewWidth;
185
+ const finalScrollLeft = Math.max(
186
+ 0,
187
+ Math.min(targetScrollLeft, maxScrollDistance)
188
+ );
189
+ setScrollLeft(finalScrollLeft);
190
+ lastScrollLeftRef.current = finalScrollLeft;
191
+ }));
167
192
  import_react.default.useEffect(() => {
168
193
  if (!currentValue || registeredTabValues.length === 0) {
169
194
  return;
170
195
  }
171
- import_taro.default.nextTick(() => __async(void 0, null, function* () {
172
- const { scrollView, scrollFields, wrapper, currentTab } = yield (0, import_queryBatch.batchQueryForScroll)({
173
- scrollViewId,
174
- wrapperId,
175
- currentTabValue: currentValue
176
- });
177
- if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
178
- return;
179
- }
180
- const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
181
- const tabWidth = currentTab.width;
182
- const containerViewWidth = scrollView.width;
183
- const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
184
- const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
185
- const maxScrollDistance = currentScrollWidth - containerViewWidth;
186
- const finalScrollLeft = Math.max(
187
- 0,
188
- Math.min(targetScrollLeft, maxScrollDistance)
189
- );
190
- setScrollLeft(finalScrollLeft);
191
- lastScrollLeftRef.current = finalScrollLeft;
192
- }));
193
- }, [currentValue, scrollViewId, wrapperId]);
196
+ import_taro.default.nextTick(() => {
197
+ centerActiveTab();
198
+ });
199
+ }, [currentValue, centerActiveTab]);
200
+ import_react.default.useEffect(() => {
201
+ if (!currentValue || registeredTabValues.length === 0) {
202
+ return;
203
+ }
204
+ import_taro.default.nextTick(() => {
205
+ centerActiveTab();
206
+ });
207
+ }, [registrationVersion, centerActiveTab]);
194
208
  const contextValue = (0, import_react.useMemo)(
195
209
  () => ({
196
210
  value: currentValue,
@@ -12,5 +12,5 @@ declare const Modal: React.ForwardRefExoticComponent<Omit<ViewProps & {
12
12
  keepMounted?: boolean;
13
13
  } & import("@bifrostui/types").ICommonProps & Omit<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
14
14
  ref?: React.Ref<HTMLDivElement>;
15
- }, "open" | "container" | keyof import("@bifrostui/types").ICommonProps | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
15
+ }, keyof import("@bifrostui/types").ICommonProps | "open" | "container" | "disablePortal" | "hideBackdrop" | "BackdropProps" | "onClose" | "disableScrollLock" | "keepMounted">, "ref"> & React.RefAttributes<HTMLDivElement>>;
16
16
  export default Modal;
@@ -101,8 +101,8 @@ const Tabs = (props) => {
101
101
  });
102
102
  const handleClick = useEventCallback(
103
103
  (e, item) => {
104
- const { index, disabled: isDisabled = false } = item;
105
- if (isDisabled || [void 0, null].includes(index))
104
+ const { index, disabled = false } = item;
105
+ if (disabled || [void 0, null].includes(index))
106
106
  return;
107
107
  if (index !== currentValue) {
108
108
  triggerValueChange(e, index);
@@ -139,33 +139,47 @@ const Tabs = (props) => {
139
139
  }
140
140
  }));
141
141
  }, [scrollViewId, registrationVersion, registeredTabValues.length]);
142
+ const centerActiveTab = useEventCallback(() => __async(void 0, null, function* () {
143
+ if (!currentValue || registeredTabValues.length === 0) {
144
+ return;
145
+ }
146
+ const { scrollView, scrollFields, wrapper, currentTab } = yield batchQueryForScroll({
147
+ scrollViewId,
148
+ wrapperId,
149
+ currentTabValue: currentValue
150
+ });
151
+ if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
152
+ return;
153
+ }
154
+ const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
155
+ const tabWidth = currentTab.width;
156
+ const containerViewWidth = scrollView.width;
157
+ const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
158
+ const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
159
+ const maxScrollDistance = currentScrollWidth - containerViewWidth;
160
+ const finalScrollLeft = Math.max(
161
+ 0,
162
+ Math.min(targetScrollLeft, maxScrollDistance)
163
+ );
164
+ setScrollLeft(finalScrollLeft);
165
+ lastScrollLeftRef.current = finalScrollLeft;
166
+ }));
142
167
  React.useEffect(() => {
143
168
  if (!currentValue || registeredTabValues.length === 0) {
144
169
  return;
145
170
  }
146
- Taro.nextTick(() => __async(void 0, null, function* () {
147
- const { scrollView, scrollFields, wrapper, currentTab } = yield batchQueryForScroll({
148
- scrollViewId,
149
- wrapperId,
150
- currentTabValue: currentValue
151
- });
152
- if (!scrollView || !scrollFields || !wrapper || !currentTab || currentTab.width === 0) {
153
- return;
154
- }
155
- const tabLeftRelativeToWrapper = currentTab.left - wrapper.left;
156
- const tabWidth = currentTab.width;
157
- const containerViewWidth = scrollView.width;
158
- const currentScrollWidth = scrollFields.scrollWidth || scrollView.width;
159
- const targetScrollLeft = tabLeftRelativeToWrapper - (containerViewWidth - tabWidth) / 2;
160
- const maxScrollDistance = currentScrollWidth - containerViewWidth;
161
- const finalScrollLeft = Math.max(
162
- 0,
163
- Math.min(targetScrollLeft, maxScrollDistance)
164
- );
165
- setScrollLeft(finalScrollLeft);
166
- lastScrollLeftRef.current = finalScrollLeft;
167
- }));
168
- }, [currentValue, scrollViewId, wrapperId]);
171
+ Taro.nextTick(() => {
172
+ centerActiveTab();
173
+ });
174
+ }, [currentValue, centerActiveTab]);
175
+ React.useEffect(() => {
176
+ if (!currentValue || registeredTabValues.length === 0) {
177
+ return;
178
+ }
179
+ Taro.nextTick(() => {
180
+ centerActiveTab();
181
+ });
182
+ }, [registrationVersion, centerActiveTab]);
169
183
  const contextValue = useMemo(
170
184
  () => ({
171
185
  value: currentValue,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bifrostui/react",
3
- "version": "2.0.0-alpha.14",
3
+ "version": "2.0.0-alpha.15",
4
4
  "description": "React components for building mobile application",
5
5
  "homepage": "http://bui.taopiaopiao.com",
6
6
  "license": "MIT",
@@ -43,10 +43,10 @@
43
43
  "clsx": "^2.1.1",
44
44
  "dayjs": "^1.11.7",
45
45
  "swiper": "^8.1.5",
46
- "@bifrostui/icons": "2.0.0-alpha.14",
47
- "@bifrostui/types": "2.0.0-alpha.14",
48
- "@bifrostui/styles": "2.0.0-alpha.14",
49
- "@bifrostui/utils": "2.0.0-alpha.14"
46
+ "@bifrostui/icons": "2.0.0-alpha.15",
47
+ "@bifrostui/styles": "2.0.0-alpha.15",
48
+ "@bifrostui/types": "2.0.0-alpha.15",
49
+ "@bifrostui/utils": "2.0.0-alpha.15"
50
50
  },
51
51
  "peerDependencies": {
52
52
  "@tarojs/components": "^3.0.0",