English | 简体中文
npm install react-native-adaptive-utils
import { YourNeed } from "react-native-adaptive-utils";
Such as, import debounce function.
import { debounce } from "react-native-adaptive-utils";
The appointed time(default 500ms
),trigger many times that execute last once.
debounce(() => {
console.log(1);
}, 500);
Means if trigger many times in 500ms
, execute last once.
The appointed time(default 500ms
), ignored triggers after first once executed.
throttle(() => {
console.log(1);
}, 500);
Means execute first once, then if trigger many times in 500ms, ignored.
Generates a random string of a specified length (32 bits by default).
let randomStr = randomString(16);
Above generate '16' length random number.
The integer is displayed in thousands of fractions
let thousandsNum = integerDecimalsFormat(-456123131.12301);
The above num format is' -456,123,131.12301 '
Counts the number of occurrences of a specified character or string in a string
let count = computeSomeCharsCount("ad", "adsfdasf");
The count above is the number of occurrences of 'AD' in 'adsfdasf'
Encapsulated in the rn Promise.all () simulation Promise.allSettled ()
allSettled(['promiseA','promiseB',...])
Returns an array containing the success or failure returns of all Promises
Verify phone no.
let checkPhoneFlag = validPhone(12);
Verify E-mail.
let checkEmailFlag = validEmail(12);
Verify Chinese card no.
let checkCardNoFlag = validCardNo(12);
Character length limit verification
let text = limitStr(str, length);
Image type verification
let isPicture = isImg(target);
Get font size base on width.
let fontSize = dynamicFontSize(12);
Suggest Usage:
const styles = StyleSheet.create({
container: {
fontSize: dynamicFontSize(12)
}
});
Check whether it is iphonex
isIphoneX() ? "..." : "...";
const styles = StyleSheet.create({
container: {
height: isIphoneX() ? 15 : 20;
}
});
### 3.3 getTitleBarHeight
Gets the title bar height based on the current screen.
#### Demo
let height = getTitleBarHeight();
const styles = StyleSheet.create({
container: {
height: getTitleBarHeight();
}
});
- Get image type.
- Determines the upper limit of input characters in the text box.
- Generate UUID.
- RN-allSettled
- Network tool.