atomicits/purescript-rnx

Platform specific components, props, styles and apis

sudhirvkumar opened this issue · 6 comments

Ideally I would like to be able to specify the Application type CrossPlatform | IOS | Android | other platforms as they become available. And we should use the type system to enforce it.

When we are building IOS app then we should be able to use only components which are cross platform and also IOS and none of the Android specific components, similarly for android.

When we are building an app which is going to be cross platform then they should be able to use only cross platform components/props/styles & api's

and in addition to the cross platform components they should be able to specify what to do when the platform is iOS or Android. Similar to Platform.select in https://facebook.github.io/react-native/docs/platform-specific-code.html#platform-specific-code

I believe PureScript Type System should enable us to do that!

Similarly, I would like to enforce the properties and styles specific to components. We should be able to use only those allowed properties for a given component... also similarly for styles.

I am ready to put more effort and use type classes and create instances as required in the library as it will improve the development time and reduce developer effort.

@doolse @pkamenarsky your comments are appreciated

I am not sure this will be possible without refactoring purescript-react first though, because ReactClass only has props as a type argument. It would probably make sense to have something like ReactClass' platform props and type ReactClass = ReactClass' Any?

Pinging @paf31

I don't think we need to make any changes to purescript-react We need to continue to use ReactElement.

I tried an experiment with type classes for the props specific to components and it worked! of course types were custom. Need to figure out a way which will be able to use the same ReactElement and Prop from purescript-react and still be able to use the type system to help us build apps better.

I have the code in office. Will attach it tomorrow. I am thinking if we can use Phanton Types to do this?

This is what I was proposing, using a phantom type on ReactClass, i.e. platform. Let me know how it turns out!

@pkamenarsky do you want to give it a try? may be a PR?

@doolse any ideas on this?

It's literally adding a type argument to ReactClass - but that means patching purescript-react, and I don't know if the author is going to agree to this.

I'd propose leaving this for last, as it's a relatively simple change and we can make a much stronger case then.