hitSlop now support a single value instead of object
How would you like to have this implemented now it's supported on Android (it was only iOS before 0.69).
For now we have to use View.edgeInsets(?~top,?~bottom,?~left,?~right, ()) and I am sure a lot of people would like to do something like View.hitSlop(5).
Maybe we could have hitSlop and hitSlopObj (to make this intuitive) ?
Feedback welcome !
In View, we could simply add
// hitSlop prop accept number and edge inset object
external hitSlop: float => edgeInsets = ""
@obj
external hitSlopObj: (
~left: float=?,
~right: float=?,
~top: float=?,
~bottom: float=?,
unit,
) => edgeInsets = ""
edgeInsets is used for other things than hitSlop, but having this shortcuts are cool imo.
No breaking change.
Any thoughts?
poke @cknitt @Freddy03h
hitSlopRect ? to be more close to React Object Type : https://reactnative.dev/docs/rect
Good point, I think we should actually define the Rect object type, as it is used in multiple places.
After #766 / with ReScript 10, we can do this as
type rect = {
left?: float,
right?: float,
top?: float,
bottom?: float,
}
Then we can have
type hitSlop
external hitSlop: float => hitSlop = ""
external hitSlopRect: rect => hitSlop = ""
I didn't follow ReScript 10, this new record annotation mean automatic Option for ? attribute?
I remember seing these for object but nor for record.
It means that these are optional record fields, i.e., they can be omitted on record initialization and will also be omitted in the generated JS.
type rect = {
left?: float,
right?: float,
top?: float,
bottom?: float,
}
let myRect = { left: 5. }
will compile to
var myRect = {
left: 5
};
I am currently preparing this (to finally release 0.69). I am replacing View.edgeInsets (for now only deprecated) by a new rect type but I am wondering where I should put it. We don't have a "global" place to put reused things like this... It will be in View module. Unless you get a better idea guys ?
Why not in types folder? In the RN doc it's just "Object Types"
If I create ObjectTypes module, this will make us write <... hitSlop={ObjectTypes.hitSlop(5.)} ... or <... hitSlop={ObjectTypes.hitSlopRect({left: 5.})} .... I found that a bit verbose but at the same time I don't see a better idea since hitSlop is a props valid for View, Pressable & Touchables...
I was thinking about a Rect module/file directly in the types folder, with the t object definition, which is enough with rescript 10.
hitSlop prop will accept a Rect.t
and refactor the View.edgeInsets to keep the same signature and return an Rect.t with a deprecated mention.
We don't need hitSlop or hitSlopRect functions.
The idea for hitSlop / hitSlopRect is because hitSlop prop accepts both float (a single value for each direction) or a Rect.t.
Is this information changing your mind ?
oops, I forgot the initial idea ^^'
I wasn't against because we already used a function, but with rescript 10 it will be unnecessary so I think it will be better not to support the float. (like React.useState only support a function and not 'shortcut' with directly the value for example).
Looking at my code, I'm always using different values for horizontals and verticals values.
So...
- I have added a
Rect.ttype that will make more sense in next release, but used in... -
View.edgeInsets(untouched for now), it will be deprecated in 0.70 with ReScript 10 breaking changes, because it will be replaced, in most place... - by
HitSlopmodule, which containst(similar but not the same asRect.t) and afloatwhich for now is a function, not an external (to avoid issue just in case somebody use HitSlop.float in a place whereView.edgeInsetsand is not an hitSlop...)
So for now: you can use HitSlop.float were View.edgeInsets. I won't communicate on this so people don't play with it for now.
In next release
- most place using
View.edgeInsetswill needHitSlop.t(but not all, since not all are hitSlop). -
Rect.t&HitSlop.twill become records with optional values, instead of[key]: option<float> -
HitSlop.floatwill become a external