1. TextInput

<TextInput style={styles.textfield}
    maxLength={2}
    placeholder="Phone Number"
    autoCapitalize="none" // sentences: first letter of each sentence (default).
    keyboardType = 'numeric' // 'default' 'email-address'
    autoCorrect={false}
    blurOnSubmit={true}
    placeholderTextColor={MKColor.Grey}
    onChangeText={(text) => this.setState({mobile: text})}
    underlineColorAndroid="rgba(0,0,0,0)"
    editable={false} 
    selectTextOnFocus={false}
    onFocus={() => console.log("focus received")}
    onBlur={() => console.log("focus lost")}
    value={this.state.mobile}
/>

2. Disable TextInput

<TextInput editable={false} selectTextOnFocus={false} />

3. TouchableOpacity

<TouchableOpacity onPress={this._onPressButton}>
  <Image
    style={styles.button}
    source={require('./myButton.png')}
  />
</TouchableOpacity>

4. Utils function 1

export async function getUserToken() {
    try {
        return (value = await AsyncStorage.getItem("access_token"));
    } catch (error) {
        console.log("Error retrieving data" + error);
        return "";
    }
}

Utils.getUserToken().then((value) => {
	// do things
});

5. Read file base64

import RNFS from 'react-native-fs';

export async function readFileBase64(filePath) {
    try {
        return (value = await RNFS.readFile(filePath, 'base64'));
    } catch (error) {
        console.log("AsyncStorage error during store use token:", error);
    }
}

let res = yield call(() => Utils.readFileBase64(chooseArray[i].path));
formData.append(`files[]`, `data:image/jpeg;base64,${res}`);

6. moment format date

import moment from 'moment';

let timestamp = new Date().getTime();
moment(timestamp).format("YYYY-MM-DD HH:mm");

7. clone array

let clonedArray = arr.slice();

8. remove an element from an array

clonedArray.splice(index, 1);
Categories: React Native

Leave a Reply

Your email address will not be published. Required fields are marked *