react-native-my-survey-sdk 2.2.3 → 2.2.4
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/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useRef, useState } from 'react';
|
|
1
|
+
import React, { useRef, useState, useEffect } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
View,
|
|
4
4
|
Text,
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
StyleSheet,
|
|
8
8
|
ScrollView,
|
|
9
9
|
Animated,
|
|
10
|
+
Keyboard,
|
|
11
|
+
Platform,
|
|
10
12
|
} from 'react-native';
|
|
11
13
|
import { XeboQuestion, XeboAnswer, XeboQuestionType } from '../models/XeboModels';
|
|
12
14
|
import { getTheme } from '../theme/XeboTheme';
|
|
@@ -24,7 +26,27 @@ export const XeboTextBoxView: React.FC<Props> = ({ question, isLastQuestion, onA
|
|
|
24
26
|
|
|
25
27
|
const [values, setValues] = useState<Record<string, string>>({});
|
|
26
28
|
const [error, setError] = useState('');
|
|
29
|
+
const [keyboardHeight, setKeyboardHeight] = useState(0);
|
|
27
30
|
const shakeAnim = useRef(new Animated.Value(0)).current;
|
|
31
|
+
const scrollRef = useRef<ScrollView>(null);
|
|
32
|
+
|
|
33
|
+
// Track keyboard height so the outer container can push button above keyboard.
|
|
34
|
+
// KAV does not work reliably inside react-native-modal on Android — this is the
|
|
35
|
+
// proven alternative: increase paddingBottom by keyboard height so content shifts up.
|
|
36
|
+
useEffect(() => {
|
|
37
|
+
const showEvent = Platform.OS === 'ios' ? 'keyboardWillShow' : 'keyboardDidShow';
|
|
38
|
+
const hideEvent = Platform.OS === 'ios' ? 'keyboardWillHide' : 'keyboardDidHide';
|
|
39
|
+
const showSub = Keyboard.addListener(showEvent, (e: { endCoordinates: { height: number } }) => setKeyboardHeight(e.endCoordinates.height));
|
|
40
|
+
const hideSub = Keyboard.addListener(hideEvent, () => setKeyboardHeight(0));
|
|
41
|
+
return () => { showSub.remove(); hideSub.remove(); };
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
// Scroll so the focused field is visible above the button when keyboard is up
|
|
45
|
+
const handleFocus = (idx: number) => {
|
|
46
|
+
setTimeout(() => {
|
|
47
|
+
scrollRef.current?.scrollTo({ y: idx * 80, animated: true });
|
|
48
|
+
}, 150);
|
|
49
|
+
};
|
|
28
50
|
|
|
29
51
|
const shake = () => {
|
|
30
52
|
Animated.sequence([
|
|
@@ -59,10 +81,11 @@ export const XeboTextBoxView: React.FC<Props> = ({ question, isLastQuestion, onA
|
|
|
59
81
|
};
|
|
60
82
|
|
|
61
83
|
return (
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
<View style={styles.outer}>
|
|
84
|
+
// paddingBottom grows to keyboard height so the button is always above the keyboard.
|
|
85
|
+
// The ScrollView above it shrinks accordingly; onFocus scrolls the active field into view.
|
|
86
|
+
<View style={[styles.outer, { paddingBottom: keyboardHeight > 0 ? keyboardHeight + 8 : 16 }]}>
|
|
65
87
|
<ScrollView
|
|
88
|
+
ref={scrollRef}
|
|
66
89
|
style={styles.scroll}
|
|
67
90
|
contentContainerStyle={styles.scrollContent}
|
|
68
91
|
keyboardShouldPersistTaps="handled"
|
|
@@ -98,6 +121,7 @@ export const XeboTextBoxView: React.FC<Props> = ({ question, isLastQuestion, onA
|
|
|
98
121
|
placeholderTextColor="#9CA3AF"
|
|
99
122
|
value={values[field.id] ?? ''}
|
|
100
123
|
onChangeText={text => handleChange(field.id, text)}
|
|
124
|
+
onFocus={() => handleFocus(idx)}
|
|
101
125
|
multiline={!isMulti}
|
|
102
126
|
numberOfLines={isMulti ? 1 : 4}
|
|
103
127
|
textAlignVertical={isMulti ? 'center' : 'top'}
|