Categories
JavaScript Answers React Native Answers

How to make text bold, italic, or underline in React Native?

Sometimes, we want to make text bold, italic, or underline in React Native.

In this article, we’ll look at how to make text bold, italic, or underline in React Native.

How to make text bold, italic, or underline in React Native?

To make text bold, italic, or underline in React Native, we can set various styles.

For instance, we write:

import * as React from 'react';
import { View, Text, StyleSheet } from 'react-native';
import { Card } from 'react-native-paper';

const styles = StyleSheet.create({
  bold: { fontWeight: 'bold' },
  italic: { fontStyle: 'italic' },
  underline: { textDecorationLine: 'underline' },
});

const App = () => {
  return (
    <View>
      <Text style={styles.bold}>bold</Text>
      <Text style={styles.italic}>italic</Text>
      <Text style={styles.underline}>underlined</Text>
    </View>
  );
};
export default App;

to create the bold style by setting fontWeight to 'bold'.

We create the italic style by setting fontStyle to 'italic'.

And we create the underline style by setting textDecorationLine to 'underline'.

Now we should see bold, italic, and underlined text ordered from top to bottom.

Conclusion

To make text bold, italic, or underline in React Native, we can set various styles.

Categories
JavaScript Answers React Native Answers

How to add border radius only for 1 corner with React Native?

Sometimes, we want to add border radius only for 1 corner with React Native.

In this article, we’ll look at how to add border radius only for 1 corner with React Native.

How to add border radius only for 1 corner with React Native?

To add border radius only for 1 corner with React Native, we can set the borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, and borderTopRightRadius individually.

For instance, we write:

import * as React from 'react';
import { View, Text } from 'react-native';
import { Card } from 'react-native-paper';

const App = () => {
  return (
    <View>
      <View
        style={{
          borderBottomLeftRadius: 5,
          borderBottomRightRadius: 0,
          borderTopLeftRadius: 0,
          borderTopRightRadius: 0,
          border: '1px solid black',
        }}>
        <Text>hello world</Text>
      </View>
    </View>
  );
};
export default App;

to set borderBottomLeftRadius to 5 and the rest to 0 to add a border radius to the bottom left corner only.

Conclusion

To add border radius only for 1 corner with React Native, we can set the borderBottomLeftRadius, borderBottomRightRadius, borderTopLeftRadius, and borderTopRightRadius individually.

Categories
JavaScript Answers React Native Answers

How to clear the React Native cache?

Sometimes, we want to clear the React Native cache.

In this article, we’ll look at how to clear the React Native cache.

How to clear the React Native cache?

To clear the React Native cache, we can run various commands.

We can clear cache from the react-native command with.

react-native start --reset-cache

With npm, we run:

npm start -- --reset-cache

And we can run Expo to clear the cache by running

expo start -c

Conclusion

To clear the React Native cache, we can run various commands.

Categories
JavaScript Answers React Native Answers

How to hide the scrollbar in a FlatList with React Native in Android?

Sometimes, we want to hide the scrollbar in a FlatList with React Native in Android.

In this article, we’ll look at how to hide the scrollbar in a FlatList with React Native in Android.

How to hide the scrollbar in a FlatList with React Native in Android?

To hide the scrollbar in a FlatList with React Native in Android, we can set the showsVerticalScrollIndicator and showsHorizontalScrollIndicator props to false.

For instance, we write:

import * as React from 'react';
import { View, FlatList, Text } from 'react-native';
import { Card } from 'react-native-paper';

const DATA = Array(100)
  .fill()
  .map((_, i) => ({ id: i, title: i }));

const Item = ({ title }) => (
  <View>
    <Text>{title}</Text>
  </View>
);

const App = () => {
  const renderItem = ({ item }) => <Item title={item.title} />;

  return (
    <View>
      <FlatList
        style={{ height: '200px' }}
        showsVerticalScrollIndicator={false}
        showsHorizontalScrollIndicator={false}
        data={DATA}
        renderItem={renderItem}
        keyExtractor={(item) => item.id}
      />
    </View>
  );
};
export default App;

to add a FlatList with the showsVerticalScrollIndicator and showsHorizontalScrollIndicator props set to false to hide the vertical and horizontal scrollbar respectively.

Conclusion

To hide the scrollbar in a FlatList with React Native in Android, we can set the showsVerticalScrollIndicator and showsHorizontalScrollIndicator props to false.

Categories
JavaScript Answers React Native Answers

How to require image module using dynamic names with React Native?

Sometimes, we want to require image module using dynamic names with React Native.

In this article, we’ll look at how to require image module using dynamic names with React Native.

How to require image module using dynamic names with React Native?

To require image module using dynamic names with React Native, we can call require with different image path strings according to another value.

For instance, we write:

import * as React from 'react';
import { View, Image, Button } from 'react-native';
import { Card } from 'react-native-paper';

const App = () => {
  const [showFirstImg, setShowFirstImg] = React.useState(true);
  return (
    <View>
      <Button title="toggle" onPress={() => setShowFirstImg((s) => !s)} />
      {showFirstImg ? (
        <Image source={require('./test1.png')} />
      ) : (
        <Image source={require('./test2.jpg')} />
      )}
    </View>
  );
};
export default App;

to add 2 Images with different source values.

We call require to include the images in the component.

And we use the showFirstImg to control which image is shown.

We add a Button to toggles the showFirstImg value when pressed.

Conclusion

To require image module using dynamic names with React Native, we can call require with different image path strings according to another value.