Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android back button for leftIcon #11

Closed
jamesholcomb opened this issue Dec 5, 2021 · 6 comments
Closed

android back button for leftIcon #11

jamesholcomb opened this issue Dec 5, 2021 · 6 comments

Comments

@jamesholcomb
Copy link
Contributor

Hi,

Trying to render a back button for Android using leftIcon and my custom <Button> component:

          leftIcon={Platform.select({
            android: (
              <Button
                onPress={navigation.goBack}
                iconStyle={{ color: "white" }}
                iconName="arrow-back"
              />
            )
          })}

but styles.leftIcon in this code

<View pointerEvents="box-none" style={styles.children}>
{leftIcon ? (
<View style={styles.leftIcon}>{leftIcon}</View>
) : (
<SearchIcon color={iconColor} style={styles.leftIcon} />
)}

seems to be meant for styling an icon and not a passed component.

What do you suggest?

@bviebahn
Copy link
Owner

bviebahn commented Dec 6, 2021

Hi,
not sure I understand correctly. Your problem is the View wrapping your custom leftIcon component right? I think it needs at least marginRight: 'auto' to look properly, but I'll have to test it. Or maybe there is a better way. I'll have a look at it tomorrow, or you can also submit a PR yourself if you want.

@jamesholcomb
Copy link
Contributor Author

Correct, the View wrapping leftIcon.

Ultimately trying to achieve this (from react-native-elements)

31585176-b124cdae-b1bd-11e7-809f-ba966cebc663

@bviebahn
Copy link
Owner

bviebahn commented Dec 7, 2021

Can you give some more information what you're having problems with? I don't see the problem with the current styling.

@jamesholcomb
Copy link
Contributor Author

jamesholcomb commented Dec 7, 2021

I tried another approach...this works to position the button:

          leftIcon={Platform.select({
            android: (
              <HeaderBackButton  /* from @react-navigation/elements@1.2.1 */
                onPress={this.onDone}
                style={{
                  position: "absolute",
                  marginLeft: -5,
                  marginTop: -5
                }}
              />
            )
          })}
          inputStyle={Platform.select({
            android: {
              marginLeft: 15,
              shadowOpacity: 0,
              shadowRadius: 0,
              shadowColor: "transparent",
              backgroundColor: "transparent"
            }
          })}

Without backgroundColor: "transparent", the android ripple will not show.

But now the hitSlop seems to be offset too far left (can only tap the button on the far left side of the icon).

EDIT: The hitSlop issue may be this: facebook/react-native#27232

@bviebahn
Copy link
Owner

bviebahn commented Dec 8, 2021

I think you don't need to use position: "absolute", but this probably won't fix your problem. It probably makes sense to remove all styling from the wrapping View except marginRight: "auto".

I was able to reproduce the android ripple problem on react-native 0.63.2 and using Expo: https://snack.expo.dev/wJBeco7qC. Setting a ripple to borderless: true causes some weird layout problems. However I couldn't reproduce it in a clean react-native project using 0.66.3, so it looks like this has been fixed. Which version are you on?

@jamesholcomb
Copy link
Contributor Author

0.65.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants