expo-snowui 1.7.73 → 1.7.74
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.
|
@@ -28,6 +28,7 @@ const step = 0.01;
|
|
|
28
28
|
// It completely breaks in Android or Web, depending on the version of react I override it to use
|
|
29
29
|
|
|
30
30
|
// After a handful of other libraries still had problems, I rolled my own
|
|
31
|
+
|
|
31
32
|
export const SnowRangeSlider = props => {
|
|
32
33
|
const {
|
|
33
34
|
SnowStyle,
|
|
@@ -47,7 +48,8 @@ export const SnowRangeSlider = props => {
|
|
|
47
48
|
trapFocusLeft: true,
|
|
48
49
|
trapFocusRight: true
|
|
49
50
|
});
|
|
50
|
-
const
|
|
51
|
+
const isInteractingRef = React.useRef(false);
|
|
52
|
+
const blockNextPropUpdateRef = React.useRef(false);
|
|
51
53
|
const isFocusedRef = React.useRef(isFocused);
|
|
52
54
|
React.useEffect(() => {
|
|
53
55
|
isFocusedRef.current = isFocused;
|
|
@@ -75,31 +77,39 @@ export const SnowRangeSlider = props => {
|
|
|
75
77
|
percentRef.current = next;
|
|
76
78
|
setPercent(next);
|
|
77
79
|
};
|
|
80
|
+
const endInteraction = () => {
|
|
81
|
+
isInteractingRef.current = false;
|
|
82
|
+
blockNextPropUpdateRef.current = true;
|
|
83
|
+
onValueChange(percentRef.current);
|
|
84
|
+
};
|
|
78
85
|
const panRef = React.useRef(PanResponder.create({
|
|
79
86
|
onStartShouldSetPanResponder: () => true,
|
|
80
87
|
onMoveShouldSetPanResponder: () => true,
|
|
81
88
|
onPanResponderGrant: event => {
|
|
82
|
-
|
|
89
|
+
isInteractingRef.current = true;
|
|
83
90
|
updateFromPageX(event.nativeEvent.pageX);
|
|
84
91
|
},
|
|
85
92
|
onPanResponderMove: event => {
|
|
86
|
-
if (!
|
|
93
|
+
if (!isInteractingRef.current) return;
|
|
87
94
|
updateFromPageX(event.nativeEvent.pageX);
|
|
88
95
|
},
|
|
89
96
|
onPanResponderRelease: () => {
|
|
90
|
-
|
|
91
|
-
onValueChange(percentRef.current);
|
|
97
|
+
endInteraction();
|
|
92
98
|
},
|
|
93
99
|
onPanResponderEnd: () => {
|
|
94
|
-
|
|
95
|
-
onValueChange(percentRef.current);
|
|
100
|
+
endInteraction();
|
|
96
101
|
}
|
|
97
102
|
}));
|
|
98
103
|
React.useEffect(() => {
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
104
|
+
if (isInteractingRef.current) {
|
|
105
|
+
return;
|
|
106
|
+
}
|
|
107
|
+
if (blockNextPropUpdateRef.current) {
|
|
108
|
+
blockNextPropUpdateRef.current = false;
|
|
109
|
+
return;
|
|
102
110
|
}
|
|
111
|
+
percentRef.current = props.percent;
|
|
112
|
+
setPercent(props.percent);
|
|
103
113
|
}, [props.percent]);
|
|
104
114
|
React.useEffect(() => {
|
|
105
115
|
percentRef.current = percent;
|
|
@@ -113,7 +123,6 @@ export const SnowRangeSlider = props => {
|
|
|
113
123
|
if (result > max) result = max;
|
|
114
124
|
percentRef.current = result;
|
|
115
125
|
setPercent(result);
|
|
116
|
-
onValueChange(result);
|
|
117
126
|
};
|
|
118
127
|
const longPress = amount => {
|
|
119
128
|
clearInterval(applyIntervalRef.current);
|
|
@@ -124,31 +133,39 @@ export const SnowRangeSlider = props => {
|
|
|
124
133
|
const actionListenerKey = addActionListener(props.focusKey ?? 'range-slider', {
|
|
125
134
|
onRight: () => {
|
|
126
135
|
if (isFocusedRef.current) {
|
|
136
|
+
isInteractingRef.current = true;
|
|
127
137
|
applyStep(step);
|
|
128
138
|
clearInterval(applyIntervalRef.current);
|
|
139
|
+
endInteraction();
|
|
129
140
|
}
|
|
130
141
|
},
|
|
131
142
|
onLongRightStart: () => {
|
|
132
143
|
if (isFocusedRef.current) {
|
|
144
|
+
isInteractingRef.current = true;
|
|
133
145
|
longPress(step * 2);
|
|
134
146
|
}
|
|
135
147
|
},
|
|
136
148
|
onLongRightEnd: () => {
|
|
137
149
|
clearInterval(applyIntervalRef.current);
|
|
150
|
+
endInteraction();
|
|
138
151
|
},
|
|
139
152
|
onLeft: () => {
|
|
140
153
|
if (isFocusedRef.current) {
|
|
154
|
+
isInteractingRef.current = true;
|
|
141
155
|
applyStep(-step);
|
|
142
156
|
clearInterval(applyIntervalRef.current);
|
|
157
|
+
endInteraction();
|
|
143
158
|
}
|
|
144
159
|
},
|
|
145
160
|
onLongLeftStart: () => {
|
|
146
161
|
if (isFocusedRef.current) {
|
|
162
|
+
isInteractingRef.current = true;
|
|
147
163
|
longPress(-step * 2);
|
|
148
164
|
}
|
|
149
165
|
},
|
|
150
166
|
onLongLeftEnd: () => {
|
|
151
167
|
clearInterval(applyIntervalRef.current);
|
|
168
|
+
endInteraction();
|
|
152
169
|
}
|
|
153
170
|
});
|
|
154
171
|
return () => removeActionListener(actionListenerKey);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","PanResponder","Platform","Pressable","View","useDebouncedCallback","useInputContext","useFocusContext","useStyleContext","jsx","_jsx","jsxs","_jsxs","min","max","step","SnowRangeSlider","props","SnowStyle","SnowConfig","addActionListener","removeActionListener","focusWrap","focusPath","isFocused","canFocus","trapFocusLeft","trapFocusRight","
|
|
1
|
+
{"version":3,"names":["React","PanResponder","Platform","Pressable","View","useDebouncedCallback","useInputContext","useFocusContext","useStyleContext","jsx","_jsx","jsxs","_jsxs","min","max","step","SnowRangeSlider","props","SnowStyle","SnowConfig","addActionListener","removeActionListener","focusWrap","focusPath","isFocused","canFocus","trapFocusLeft","trapFocusRight","isInteractingRef","useRef","blockNextPropUpdateRef","isFocusedRef","useEffect","current","percent","setPercent","useState","percentRef","applyStepInterval","setApplyStepInterval","applyIntervalRef","trackRef","trackXRef","sliderWidth","component","rangeSlider","trackWrapper","width","onValueChange","debounce","inputDebounceMilliseconds","clamp","v","Math","updateFromPageX","pageX","x","next","endInteraction","panRef","create","onStartShouldSetPanResponder","onMoveShouldSetPanResponder","onPanResponderGrant","event","nativeEvent","onPanResponderMove","onPanResponderRelease","onPanResponderEnd","applyStep","amount","result","longPress","clearInterval","setInterval","actionListenerKey","focusKey","onRight","onLongRightStart","onLongRightEnd","onLeft","onLongLeftStart","onLongLeftEnd","thumbX","trackWrapperStyle","leftTrackStyle","leftTrack","thumbStyle","thumb","left","push","backgroundColor","color","hover","borderColor","hoverDark","style","wrapper","children","ref","onLayout","measureInWindow","panHandlers","rightTrack","parentPath"],"sourceRoot":"../../../../src","sources":["component/wired/snow-range-slider.js"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACIC,YAAY,EACZC,QAAQ,EACRC,SAAS,EACTC,IAAI,QACD,cAAc;AACrB,SAASC,oBAAoB,QAAQ,cAAc;AACnD,SAASC,eAAe,QAAQ,qCAAkC;AAClE,SAASC,eAAe,QAAQ,qCAAkC;AAClE,SAASC,eAAe,QAAQ,qCAAkC;AAAA,SAAAC,GAAA,IAAAC,IAAA,EAAAC,IAAA,IAAAC,KAAA;AAElE,MAAMC,GAAG,GAAG,GAAG;AACf,MAAMC,GAAG,GAAG,GAAG;AACf,MAAMC,IAAI,GAAG,IAAI;;AAEjB;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;;AAEA;AACA;;AAEA;AACA;;AAEA;;AAEA,OAAO,MAAMC,eAAe,GAAIC,KAAK,IAAK;EACtC,MAAM;IAAEC,SAAS;IAAEC;EAAW,CAAC,GAAGX,eAAe,CAACS,KAAK,CAAC;EACxD,MAAM;IAAEG,iBAAiB;IAAEC;EAAqB,CAAC,GAAGf,eAAe,CAAC,CAAC;EACrE,MAAM;IACFgB,SAAS;IACTC,SAAS;IACTC;EACJ,CAAC,GAAGjB,eAAe,CAAC,QAAQ,EAAE;IAC1B,GAAGU,KAAK;IACRQ,QAAQ,EAAE,IAAI;IACdC,aAAa,EAAE,IAAI;IACnBC,cAAc,EAAE;EACpB,CAAC,CAAC;EAEF,MAAMC,gBAAgB,GAAG5B,KAAK,CAAC6B,MAAM,CAAC,KAAK,CAAC;EAC5C,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A,CAACN,IAAI;QAAC4F,KAAK,EAAE9E,SAAS,CAAC0B,SAAS,CAACC,WAAW,CAAC0D;MAAW,CAAE,CAAC,EAC1DjF,SAAS,cAACZ,IAAA,CAACP,SAAS;QACjB6F,KAAK,EAAET,UAAW;QAClBX,QAAQ,EAAE,OAAQ;QAClB4B,UAAU,EAAEjF;MAAU,CACzB,CAAC,CAAC;IAAA,CACD;EAAC,CACL,CAAC;AAEf,CAAC;AAED,eAAeP,eAAe","ignoreList":[]}
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import React from "react"
|
|
1
|
+
import React from "react"
|
|
2
2
|
import {
|
|
3
3
|
PanResponder,
|
|
4
4
|
Platform,
|
|
5
5
|
Pressable,
|
|
6
6
|
View
|
|
7
|
-
} from "react-native"
|
|
7
|
+
} from "react-native"
|
|
8
8
|
import { useDebouncedCallback } from 'use-debounce'
|
|
9
9
|
import { useInputContext } from '../../context/snow-input-context'
|
|
10
10
|
import { useFocusContext } from '../../context/snow-focus-context'
|
|
@@ -31,6 +31,7 @@ const step = 0.01
|
|
|
31
31
|
// It completely breaks in Android or Web, depending on the version of react I override it to use
|
|
32
32
|
|
|
33
33
|
// After a handful of other libraries still had problems, I rolled my own
|
|
34
|
+
|
|
34
35
|
export const SnowRangeSlider = (props) => {
|
|
35
36
|
const { SnowStyle, SnowConfig } = useStyleContext(props)
|
|
36
37
|
const { addActionListener, removeActionListener } = useInputContext()
|
|
@@ -45,7 +46,9 @@ export const SnowRangeSlider = (props) => {
|
|
|
45
46
|
trapFocusRight: true
|
|
46
47
|
})
|
|
47
48
|
|
|
48
|
-
const
|
|
49
|
+
const isInteractingRef = React.useRef(false)
|
|
50
|
+
const blockNextPropUpdateRef = React.useRef(false)
|
|
51
|
+
|
|
49
52
|
const isFocusedRef = React.useRef(isFocused)
|
|
50
53
|
React.useEffect(() => { isFocusedRef.current = isFocused }, [isFocused])
|
|
51
54
|
const [percent, setPercent] = React.useState(() => typeof props.percent === 'number' ? props.percent : 0)
|
|
@@ -77,38 +80,49 @@ export const SnowRangeSlider = (props) => {
|
|
|
77
80
|
setPercent(next)
|
|
78
81
|
}
|
|
79
82
|
|
|
83
|
+
const endInteraction = () => {
|
|
84
|
+
isInteractingRef.current = false
|
|
85
|
+
blockNextPropUpdateRef.current = true
|
|
86
|
+
onValueChange(percentRef.current)
|
|
87
|
+
}
|
|
88
|
+
|
|
80
89
|
const panRef = React.useRef(
|
|
81
90
|
PanResponder.create({
|
|
82
91
|
onStartShouldSetPanResponder: () => true,
|
|
83
92
|
onMoveShouldSetPanResponder: () => true,
|
|
84
93
|
|
|
85
94
|
onPanResponderGrant: (event) => {
|
|
86
|
-
|
|
95
|
+
isInteractingRef.current = true
|
|
87
96
|
updateFromPageX(event.nativeEvent.pageX)
|
|
88
97
|
},
|
|
89
98
|
|
|
90
99
|
onPanResponderMove: (event) => {
|
|
91
|
-
if (!
|
|
100
|
+
if (!isInteractingRef.current) return
|
|
92
101
|
updateFromPageX(event.nativeEvent.pageX)
|
|
93
102
|
},
|
|
94
103
|
|
|
95
104
|
onPanResponderRelease: () => {
|
|
96
|
-
|
|
97
|
-
onValueChange(percentRef.current)
|
|
105
|
+
endInteraction()
|
|
98
106
|
},
|
|
99
107
|
|
|
100
108
|
onPanResponderEnd: () => {
|
|
101
|
-
|
|
102
|
-
onValueChange(percentRef.current)
|
|
109
|
+
endInteraction()
|
|
103
110
|
}
|
|
104
111
|
})
|
|
105
112
|
)
|
|
106
113
|
|
|
107
114
|
React.useEffect(() => {
|
|
108
|
-
if (
|
|
109
|
-
|
|
110
|
-
setPercent(props.percent)
|
|
115
|
+
if (isInteractingRef.current) {
|
|
116
|
+
return
|
|
111
117
|
}
|
|
118
|
+
|
|
119
|
+
if (blockNextPropUpdateRef.current) {
|
|
120
|
+
blockNextPropUpdateRef.current = false
|
|
121
|
+
return
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
percentRef.current = props.percent
|
|
125
|
+
setPercent(props.percent)
|
|
112
126
|
}, [props.percent])
|
|
113
127
|
|
|
114
128
|
React.useEffect(() => {
|
|
@@ -125,7 +139,6 @@ export const SnowRangeSlider = (props) => {
|
|
|
125
139
|
if (result > max) result = max
|
|
126
140
|
percentRef.current = result
|
|
127
141
|
setPercent(result)
|
|
128
|
-
onValueChange(result)
|
|
129
142
|
}
|
|
130
143
|
|
|
131
144
|
const longPress = (amount) => {
|
|
@@ -133,35 +146,44 @@ export const SnowRangeSlider = (props) => {
|
|
|
133
146
|
applyStep(amount)
|
|
134
147
|
setApplyStepInterval(setInterval(() => applyStep(amount), 100))
|
|
135
148
|
}
|
|
149
|
+
|
|
136
150
|
React.useEffect(() => {
|
|
137
151
|
const actionListenerKey = addActionListener(props.focusKey ?? 'range-slider', {
|
|
138
152
|
onRight: () => {
|
|
139
153
|
if (isFocusedRef.current) {
|
|
154
|
+
isInteractingRef.current = true
|
|
140
155
|
applyStep(step)
|
|
141
156
|
clearInterval(applyIntervalRef.current)
|
|
157
|
+
endInteraction()
|
|
142
158
|
}
|
|
143
159
|
},
|
|
144
160
|
onLongRightStart: () => {
|
|
145
161
|
if (isFocusedRef.current) {
|
|
162
|
+
isInteractingRef.current = true
|
|
146
163
|
longPress(step * 2)
|
|
147
164
|
}
|
|
148
165
|
},
|
|
149
166
|
onLongRightEnd: () => {
|
|
150
167
|
clearInterval(applyIntervalRef.current)
|
|
168
|
+
endInteraction()
|
|
151
169
|
},
|
|
152
170
|
onLeft: () => {
|
|
153
171
|
if (isFocusedRef.current) {
|
|
172
|
+
isInteractingRef.current = true
|
|
154
173
|
applyStep(-step)
|
|
155
174
|
clearInterval(applyIntervalRef.current)
|
|
175
|
+
endInteraction()
|
|
156
176
|
}
|
|
157
177
|
},
|
|
158
178
|
onLongLeftStart: () => {
|
|
159
179
|
if (isFocusedRef.current) {
|
|
180
|
+
isInteractingRef.current = true
|
|
160
181
|
longPress(-step * 2)
|
|
161
182
|
}
|
|
162
183
|
},
|
|
163
184
|
onLongLeftEnd: () => {
|
|
164
185
|
clearInterval(applyIntervalRef.current)
|
|
186
|
+
endInteraction()
|
|
165
187
|
},
|
|
166
188
|
})
|
|
167
189
|
return () => removeActionListener(actionListenerKey)
|
|
@@ -215,4 +237,4 @@ export const SnowRangeSlider = (props) => {
|
|
|
215
237
|
)
|
|
216
238
|
}
|
|
217
239
|
|
|
218
|
-
export default SnowRangeSlider
|
|
240
|
+
export default SnowRangeSlider
|