hotwired / hotwire-native-android

Hotwire Native for Android
MIT License
41 stars 5 forks source link

File `<input>` field is inconsistent with iOS #30

Closed joemasilotti closed 7 months ago

joemasilotti commented 7 months ago

When using an <input type="file"/> field the behavior on Android is inconsistent with iOS.

Default <input> field

A default <input> file field produces the following on iOS, with options for all three pickers: Photo Library, Take Photo, and Choose File.

<input type="file" accept="image/*"/>
Input field Three options
RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_06 53 44 RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_06 53 46

Selecting each option, in turn, produces the correct picker.

Photo Library Take Photo Choose File
RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_06 53 48 RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_06 53 53 RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_06 53 57

The same markup on Android navigates the user directly to the photo library picker.

Input field Photo Library
Xnapper-2024-04-06-06 54 02 Xnapper-2024-04-06-06 55 00

The capture attribute

Adding capture to the <input> field adds the additional camera option to Android.

<input type="file" accept="image/*" capture/>
Input field Two options
Xnapper-2024-04-06-07 02 20 Xnapper-2024-04-06-07 02 32

However, on iOS adding the capture attribute skips the options selection and goes directly to the camera.

Input field Take Photo
RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_07 04 39 RocketSim_Screenshot_iPhone_15_Pro_6 1_2024-04-06_07 04 47

According to the documentation, capture should have a value of user or environment. It doesn't seem to matter what value, if any, is set. The same behavior described above occurs on both platforms.

It's worth nothing that there is zero custom Swift code related to handling these fields - everything is coming directly from WKWebView. It looks like Android has code related to "capturing" but I couldn't figure out why some intents would show when others wouldn't.

jayohms commented 7 months ago

Fixed here: https://github.com/hotwired/hotwire-native-android/pull/31