@kaushverse/pickify 1.1.10 → 1.1.12

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.
package/dist/index.js CHANGED
@@ -291,30 +291,46 @@ function MultiPickerGroup({
291
291
  renderGroupIcon,
292
292
  defaultOpen = false
293
293
  }) {
294
- const [open, setOpen] = (0, import_react2.useState)(false);
294
+ const [open, setOpen] = (0, import_react2.useState)(defaultOpen);
295
295
  const [contentHeight, setContentHeight] = (0, import_react2.useState)(0);
296
- const [isMeasured, setIsMeasured] = (0, import_react2.useState)(false);
296
+ const [isInitialized, setIsInitialized] = (0, import_react2.useState)(false);
297
297
  const animatedHeight = (0, import_react2.useRef)(new import_react_native2.Animated.Value(0)).current;
298
+ const animationRef = (0, import_react2.useRef)(null);
298
299
  (0, import_react2.useEffect)(() => {
299
- if (defaultOpen && contentHeight > 0 && !isMeasured) {
300
- setIsMeasured(true);
301
- animatedHeight.setValue(contentHeight);
302
- setOpen(true);
300
+ if (contentHeight > 0 && !isInitialized) {
301
+ setIsInitialized(true);
302
+ if (defaultOpen) {
303
+ animatedHeight.setValue(contentHeight);
304
+ setOpen(true);
305
+ }
306
+ }
307
+ }, [contentHeight, defaultOpen, animatedHeight, isInitialized]);
308
+ const toggle = (0, import_react2.useCallback)(() => {
309
+ if (animationRef.current) {
310
+ animationRef.current.stop();
303
311
  }
304
- }, [contentHeight, defaultOpen, isMeasured]);
305
- const toggle = () => {
306
- if (contentHeight === 0) return;
307
312
  const newOpenState = !open;
308
313
  const toValue = newOpenState ? contentHeight : 0;
309
- import_react_native2.Animated.timing(animatedHeight, {
314
+ animationRef.current = import_react_native2.Animated.timing(animatedHeight, {
310
315
  toValue,
311
316
  duration: 250,
312
317
  useNativeDriver: false
313
- }).start(() => {
318
+ });
319
+ animationRef.current.start(() => {
314
320
  setOpen(newOpenState);
321
+ animationRef.current = null;
315
322
  });
316
323
  setOpen(newOpenState);
317
- };
324
+ }, [open, contentHeight, animatedHeight]);
325
+ const handleLayout = (0, import_react2.useCallback)(
326
+ (event) => {
327
+ const height = event.nativeEvent.layout.height;
328
+ if (height > 0 && height !== contentHeight) {
329
+ setContentHeight(height);
330
+ }
331
+ },
332
+ [contentHeight]
333
+ );
318
334
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_react_native2.View, { style: styles.group, children: [
319
335
  /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(
320
336
  import_react_native2.TouchableOpacity,
@@ -335,14 +351,9 @@ function MultiPickerGroup({
335
351
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
336
352
  import_react_native2.View,
337
353
  {
338
- style: styles.hidden,
354
+ style: styles.measureContainer,
355
+ onLayout: handleLayout,
339
356
  pointerEvents: "none",
340
- onLayout: (e) => {
341
- const height = e.nativeEvent.layout.height;
342
- if (height > 0 && height !== contentHeight) {
343
- setContentHeight(height);
344
- }
345
- },
346
357
  children
347
358
  }
348
359
  ),
@@ -371,8 +382,8 @@ var styles = import_react_native2.StyleSheet.create({
371
382
  flexDirection: "row",
372
383
  justifyContent: "space-between",
373
384
  alignItems: "center",
374
- paddingVertical: 12,
375
- paddingHorizontal: 8,
385
+ paddingVertical: 14,
386
+ paddingHorizontal: 12,
376
387
  backgroundColor: "#F9FAFB",
377
388
  borderRadius: 8
378
389
  },
@@ -385,11 +396,11 @@ var styles = import_react_native2.StyleSheet.create({
385
396
  overflow: "hidden"
386
397
  },
387
398
  content: {
388
- marginTop: 6,
389
- paddingHorizontal: 8,
390
- paddingBottom: 4
399
+ paddingTop: 8,
400
+ paddingBottom: 4,
401
+ paddingHorizontal: 12
391
402
  },
392
- hidden: {
403
+ measureContainer: {
393
404
  position: "absolute",
394
405
  opacity: 0,
395
406
  zIndex: -1,
@@ -535,7 +546,7 @@ function MultiPickerModal({
535
546
  {
536
547
  label: group.label,
537
548
  renderGroupIcon,
538
- defaultOpen: false,
549
+ defaultOpen: index === 0,
539
550
  children: group.data.map((item) => /* @__PURE__ */ (0, import_jsx_runtime4.jsx)(
540
551
  MultiPickerItem,
541
552
  {
@@ -684,7 +695,7 @@ var defaultStyles3 = import_react_native4.StyleSheet.create({
684
695
  borderTopLeftRadius: 20,
685
696
  borderTopRightRadius: 20,
686
697
  maxHeight: "70%",
687
- minHeight: "40%"
698
+ minHeight: "20%"
688
699
  },
689
700
  scrollContent: {
690
701
  paddingBottom: 20
package/dist/index.mjs CHANGED
@@ -255,7 +255,7 @@ var toggleValue = (arr, value) => {
255
255
  };
256
256
 
257
257
  // src/components/MultiPickerGroup.tsx
258
- import { useRef, useState as useState2, useEffect as useEffect2 } from "react";
258
+ import { useRef, useState as useState2, useEffect as useEffect2, useCallback } from "react";
259
259
  import {
260
260
  View as View2,
261
261
  Text as Text2,
@@ -270,30 +270,46 @@ function MultiPickerGroup({
270
270
  renderGroupIcon,
271
271
  defaultOpen = false
272
272
  }) {
273
- const [open, setOpen] = useState2(false);
273
+ const [open, setOpen] = useState2(defaultOpen);
274
274
  const [contentHeight, setContentHeight] = useState2(0);
275
- const [isMeasured, setIsMeasured] = useState2(false);
275
+ const [isInitialized, setIsInitialized] = useState2(false);
276
276
  const animatedHeight = useRef(new Animated.Value(0)).current;
277
+ const animationRef = useRef(null);
277
278
  useEffect2(() => {
278
- if (defaultOpen && contentHeight > 0 && !isMeasured) {
279
- setIsMeasured(true);
280
- animatedHeight.setValue(contentHeight);
281
- setOpen(true);
279
+ if (contentHeight > 0 && !isInitialized) {
280
+ setIsInitialized(true);
281
+ if (defaultOpen) {
282
+ animatedHeight.setValue(contentHeight);
283
+ setOpen(true);
284
+ }
285
+ }
286
+ }, [contentHeight, defaultOpen, animatedHeight, isInitialized]);
287
+ const toggle = useCallback(() => {
288
+ if (animationRef.current) {
289
+ animationRef.current.stop();
282
290
  }
283
- }, [contentHeight, defaultOpen, isMeasured]);
284
- const toggle = () => {
285
- if (contentHeight === 0) return;
286
291
  const newOpenState = !open;
287
292
  const toValue = newOpenState ? contentHeight : 0;
288
- Animated.timing(animatedHeight, {
293
+ animationRef.current = Animated.timing(animatedHeight, {
289
294
  toValue,
290
295
  duration: 250,
291
296
  useNativeDriver: false
292
- }).start(() => {
297
+ });
298
+ animationRef.current.start(() => {
293
299
  setOpen(newOpenState);
300
+ animationRef.current = null;
294
301
  });
295
302
  setOpen(newOpenState);
296
- };
303
+ }, [open, contentHeight, animatedHeight]);
304
+ const handleLayout = useCallback(
305
+ (event) => {
306
+ const height = event.nativeEvent.layout.height;
307
+ if (height > 0 && height !== contentHeight) {
308
+ setContentHeight(height);
309
+ }
310
+ },
311
+ [contentHeight]
312
+ );
297
313
  return /* @__PURE__ */ jsxs2(View2, { style: styles.group, children: [
298
314
  /* @__PURE__ */ jsxs2(
299
315
  TouchableOpacity2,
@@ -314,14 +330,9 @@ function MultiPickerGroup({
314
330
  /* @__PURE__ */ jsx2(
315
331
  View2,
316
332
  {
317
- style: styles.hidden,
333
+ style: styles.measureContainer,
334
+ onLayout: handleLayout,
318
335
  pointerEvents: "none",
319
- onLayout: (e) => {
320
- const height = e.nativeEvent.layout.height;
321
- if (height > 0 && height !== contentHeight) {
322
- setContentHeight(height);
323
- }
324
- },
325
336
  children
326
337
  }
327
338
  ),
@@ -350,8 +361,8 @@ var styles = StyleSheet2.create({
350
361
  flexDirection: "row",
351
362
  justifyContent: "space-between",
352
363
  alignItems: "center",
353
- paddingVertical: 12,
354
- paddingHorizontal: 8,
364
+ paddingVertical: 14,
365
+ paddingHorizontal: 12,
355
366
  backgroundColor: "#F9FAFB",
356
367
  borderRadius: 8
357
368
  },
@@ -364,11 +375,11 @@ var styles = StyleSheet2.create({
364
375
  overflow: "hidden"
365
376
  },
366
377
  content: {
367
- marginTop: 6,
368
- paddingHorizontal: 8,
369
- paddingBottom: 4
378
+ paddingTop: 8,
379
+ paddingBottom: 4,
380
+ paddingHorizontal: 12
370
381
  },
371
- hidden: {
382
+ measureContainer: {
372
383
  position: "absolute",
373
384
  opacity: 0,
374
385
  zIndex: -1,
@@ -514,7 +525,7 @@ function MultiPickerModal({
514
525
  {
515
526
  label: group.label,
516
527
  renderGroupIcon,
517
- defaultOpen: false,
528
+ defaultOpen: index === 0,
518
529
  children: group.data.map((item) => /* @__PURE__ */ jsx4(
519
530
  MultiPickerItem,
520
531
  {
@@ -663,7 +674,7 @@ var defaultStyles3 = StyleSheet4.create({
663
674
  borderTopLeftRadius: 20,
664
675
  borderTopRightRadius: 20,
665
676
  maxHeight: "70%",
666
- minHeight: "40%"
677
+ minHeight: "20%"
667
678
  },
668
679
  scrollContent: {
669
680
  paddingBottom: 20
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kaushverse/pickify",
3
- "version": "1.1.10",
3
+ "version": "1.1.12",
4
4
  "description": "A fully customizable React Native picker with search, multi-select, grouping, and async support.",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",