Badal S
Badal S

Reputation: 567

Onpress() of native-base Button is not working on Android

I am using the native-base button and trying to download the image by pressing the button. It's is working perfectly fine in IOS but not working in Android. Here is my code

        <View
            style={{
              marginVertical: hp("2%"),
              marginHorizontal: wp("15%"),
              textAlign: "center",
              width: "100%",
            }}
          >
            <Button
              onPress={() => downloadFile()}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >
              <Text
                style={{
                  color: "black",
                  fontSize: RFPercentage(2.1),
                  fontFamily: "BalsamiqSansBold",
                }}
              >
                ADD TO PHOTOS
              </Text>
            </Button>
          </View>

The downloadFile() function is called in IOS when the button is being pressed but it's not working in the case of Android.

I also tried console logging on press like this

          <Button
              onPress={() => console.log("Button Clicked")}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >

It's working in IOS but not in the case of Android.

Also if I directly call the function on onPress like this in Android it automatically logs Button Clicked without being pressed. I tried to figure all the possible ways to resolve it but I am not getting the exact cause of this issue.

         <Button
              onPress={console.log("Button Clicked")}
              style={{
                backgroundColor: "#fff",
                width: "60%",
                borderRadius: 0,
              }}
              block
            >

Upvotes: 2

Views: 1155

Answers (2)

Ho&#224;ng L&#226;m
Ho&#224;ng L&#226;m

Reputation: 480

import {TouchableOpacity } from 'react-native'
     
<TouchableOpacity
                style={styles.button}
                onPress={handleSaveLimitValue}
              >
                <Text
                  color={colors.white}
                  weight={TextWeight.DEMI_BOLD}
                  size={16}
                  style={styles.buttonText}
                >
                  Save
                </Text>
              </TouchableOpacity>

Using TouchableOpacity of native module worked for me instead of using import {BaseButton} from react-native-gesture-handler

Hope my answer may help you.

Upvotes: 0

Awais Ibrar
Awais Ibrar

Reputation: 635

Maybe you are facing an issue regarding TouchableOpacity in android.

You can import ToucahableOpacity from 'react-native-gesture-handler' and hopefully this will help a lot.

You can import like this

import {TouchableOpacity} from 'react-native-gesture-handler'

Upvotes: 0

Related Questions