-
Notifications
You must be signed in to change notification settings - Fork 111
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
Allow further customization by allowing component replacement #141
Comments
I think that a simpler approach may be to allow users to pass in their own |
@slapbox Yeah, I also prefer letting user pass down theit own component... which, technically you can already do. The container allows you to pass down any component (but it does some checks on the component name/type to determine the style) |
Thanks for your reply @mmazzarolo! I hadn't thought to customize as you've mentioned, but that makes sense! I was thinking about a slightly different implementation that would allow users to benefit from your hard work more, with less custom code required for end users. For example, users could pass their own custom input to const Input = props => {
return (
<DialogDefault.Input
labelComponent={CustomLabelComponent}
inputComponent={CustomInputComponent}
{...props}
/>
);
};
export const Dialog = {
Input,
Container,
// ... etc
} That way all of the default styling you've worked so hard to make match the native OS dialogs would still be applied to the custom components. Sort of like what React-Select does, but of course with many fewer options than they offer. Thoughts? Alternatively, if there were a way to force |
@mmazzarolo how does that switch statement you linked to actually work? I've tried implementing custom components in line with your suggestion but I can't get them to end up anywhere other than I try setting If the The fact the Any advice would be hugely appreciated! Thank you again for this great package. |
Yeah. That totally makes sense to me, and it's something I thought about in the past. I just wasn't able to find a nice API to suit this use case.
Sorry, I'm missing one thing: is the component being part of |
Unfortunately yes, as it breaks the side-by-side buttons on Android. If not for that, it would be entirely workable.
That looks interesting! We'll probably end up using it! Since you already have implemented a similar API, but you say you weren't able to find a nice API for this use case for
Very appreciative of all of your support and guidance! I'll be happy to work on this if we can find a good path forward, but I'm not well versed in Typescript so my work would likely need some cleanup before it can be merged. I think we should prioritize in these terms:
Do you have any ideas why my react-native-dialog/src/Container.tsx Line 176 in 0df53e3
If we go for the custom component route, I'm thinking that a user would pass the custom components like in the code above |
Actually, I'm thinking I screwed up yesterday in my testing of whether setting |
Nope, unfortunately something else seems to be at issue. Maybe you can tell what? I made a branch on my fork with the code changes I thought would be necessary for supporting an |
Is there any way around our buttons ending up in Maybe a simple tweak to this code would be the easiest to allow customization for now? react-native-dialog/src/Container.tsx Lines 63 to 90 in 0df53e3
|
Hola @slapbox ! I'm fine with making that flow customizable though.
In this way you can customize the children layout flow while still allowing to re-use the default behaviour, if needed 👍 |
Thanks for your reply! I think that makes sense! The only this that doesn't make sense to me is that adding The best solution, in my view, would be if this worked as it apparently should. I wondered if it might somehow be related to the usage of From an earlier comment:
Very strange! |
It looks like this code would work. The only changes here are to add What do you think about this approach? Would you accept a PR for it? It would keep the API simpler than the other approaches we discussed. React.Children.forEach(children, (child) => {
if (typeof child === "object" && child !== null && "type" in child) {
switch (child.type.displayName) {
case DialogTitle.displayName:
titleChildrens.push(child as TitleElement);
return;
case DialogDescription.displayName:
descriptionChildrens.push(child as DescriptionElement);
return;
case DialogButton.displayName:
if (Platform.OS === "ios" && buttonChildrens.length > 0) {
buttonChildrens.push(
<View
style={[
verticalButtons
? styles.buttonSeparatorVertical
: styles.buttonSeparatorHorizontal,
buttonSeparatorStyle,
]}
/>
);
}
buttonChildrens.push(child as ButtonElement);
return;
}
}
otherChildrens.push(child);
}); That would resolve the primary issue we were facing. It would leave the issue of custom In our case we have a export const TextInput = forwardRef((props, ref) => {
const theme = useTheme();
const { text, selection } = theme.activeMode();
return (
<StyledTextInput
placeholderTextColor={getPlaceholderColor(text)}
ref={ref}
style={props.style}
underlineColorAndroid={props.underlineColorAndroid || 'transparent'}
selectionColor={selection.text}
{...props}
/>
);
}); |
Generally, I'm not a fan of merging things without knowing why/how they work... |
And thanks so much for keeping up with the discussion 👍 |
This fixes a sub-issue raised within mmazzarolo#141: mmazzarolo#141 (comment)
@mmazzarolo thanks for your knowledge in this discussion and all the hard work you've done. I've submitted a PR for the I understand the desire not to complicate things with allowing custom components to be passed. I think what I'll likely end up doing is forking the repo and adding our own changes to support a custom Unfortunately that would still leave the Otherwise end users can style everything else properly, but labels remain untargetable and end up as black text on black background. I know you don't want to allow for any more styling/customization than is strictly necessary, but supporting that until/unless there's a way to force Thanks again for the great work! |
@slapbox after thinking about it a bit more, I agree with your point. I think it's fine to "temporarily" support the customization of stuff we can't automatically customize yet. |
Yup, will do! It might be a few days or even a bit longer before I can get it done, but it's on my list along with fixing #143. What do you think of the naming convention, |
I'm fine either way 👍 |
This can be closed once #150 is reviewed and merged. |
Ask your Question
I'm trying to implement custom styles for when users use dark/light mode and the system is set to the opposite color scheme - but I've hit a wall with trying to style the inputs. Is there any way to modify the text color of the labels? Right now we have black on dark gray, but would like to change that to white without having to fork the entire package to do it.
The text was updated successfully, but these errors were encountered: