react-native/Examples/UIExplorer
Nick Lockwood e7005f7f54 Fixed missing rows on UIExplorer <ListView> - Grid Layout example
Summary:
public
I was looking into the missing panels at the bottom of the <ListView> - Grid Layout example, and found that it was caused by several problems, some in the example and some in ListView itself.

The first problem seemed to be a bug in the `_getDistanceFromEnd()` method, which calculates whether the ListView needs to load more content based on the distance of the visible content from the bottom of the scrollview. This was previously using the function

    Math.max(scrollProperties.contentLength, scrollProperties.visibleLength) - scrollProperties.visibleLength - scrollProperties.offset

to calculate the amount the user could scroll before they run out of content. This sort-of works in most cases because `scrollProperties.contentLength` is usually longer than `scrollProperties.visibleLength`, so this would generally evaluate to

    scrollProperties.contentLength - scrollProperties.visibleLength - scrollProperties.offset

which meant that it would be positive as long as there was content still to be displayed offscreen, and negative when you reached the end of the content. This logic breaks down if `contentLength` is less than `visibleLength`, however. For example, if you have 300pts of content loaded, and your scrollView is 500pts tall, and your scroll position is zero, this evaluates to

    Math.max(300, 500) - 500 - 0 = 0

In other words, the algorithm is saying that you have zero pts of scroll content remaining before you need to reload. But actually, the bottom 200pts of the screen are empty, so you're really 200pts in debt, and need to load extra rows to fill that space. The correct algorithm is simply to get rid of the `Math.max` and just use

    scrollProperties.contentLength - scrollProperties.visibleLength - scrollProperties.offset

I originally thought that this was the cause of the gap, but it isn't, because ListView has `DEFAULT_SCROLL_RENDER_AHEAD = 1000`, which means that it tries to load at least 1000pts more content than is currently visible, to avoid gaps. This masked the bug, so in practice it wasn't causing an issue.

The next problem I found was that there is an implict assumption in ListView that the first page of content you load is sufficient to cover the screen, or rather, that the first _ second page is sufficient. The constants `DEFAULT_INITIAL_ROWS = 10` and `DEFAULT_PAGE_SIZE = 1`, mean that when the ListView first loads, the following happens:

    1. It loads 10 rows of content.
    2. It checks if `_getDistanceFromEnd() < DEFAULT_SCROLL_RENDER_AHEAD` (1000).
    3. If it is, it loads another `DEFAULT_PAGE_SIZE` rows of content, then stops.

In the case of the ListView Grid Layout example, this meant that it first loaded 10 cells, then loaded another 1, for a total of 11. The problem was that going from 10 to 11 cells isn't sufficient to fill the visible scroll area, and it doesn't change the `contentSize` (since the cells wrap onto the same line), and since ListView doesn't try to load any more until the `contentSize` or `scrollOffset ` changes, it stops loading new rows at that point.

I tried fixing this by calling `_renderMoreRowsIfNeeded()` after `_pageInNewRows()` so that it will continue to fetch new rows until the `_getDistanceFromEnd()` is less than the threshold, rather than stopping after the first page and waiting until the `contentSize` or `scrollOffset` change, but although this solves the problem for the Grid Layout example, it leads to over-fetching in the more common case of a standard row-based ListView.

In the end, I just increased the `pageSize` to 3 for the Grid Layout example, which makes more sense anyway since loading a page that is not a multiple of the number of cells per row confuses the `_renderMoreRowsIfNeeded` algorithm, and leads to gaps at the bottom of the view.

This solved the problem, however there was still a "pop-in" effect, where the additional rows were paged in after the ListView appeared. This was simply a misconfiguration in the example itself: The default of 10 rows was insufficient to fill the screen, so I changed the `initialListSize` prop to `20`.

Reviewed By: javache

Differential Revision: D2911690

fb-gh-sync-id: 8d6bd78843335fb091e7e24f7c2e6a416b0321d3
shipit-source-id: 8d6bd78843335fb091e7e24f7c2e6a416b0321d3
2016-02-10 08:37:57 -08:00
..
AnimatedGratuitousApp Fix missing keys in animation example 2016-01-06 11:12:30 -08:00
NavigationExperimental Navigation Back support and examples for Android 2016-02-08 20:03:31 -08:00
Navigator PixelRatio.pixel() 2016-01-15 05:15:31 -08:00
Thumbnails Fixed zero-size images 2015-11-18 15:23:30 -08:00
UIExplorer Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00
UIExplorer.xcodeproj Generalized image decoding and resizing logic 2016-01-20 11:11:13 -08:00
UIExplorerIntegrationTests Update examples for the converged Switch component 2016-01-11 12:46:50 -08:00
UIExplorerUnitTests flush events queue when an event cannot be coalesced (4/7) 2016-02-03 05:23:55 -08:00
android/app Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00
AccessibilityAndroidExample.android.js Release React Native for Android 2015-09-14 18:13:39 +01:00
AccessibilityIOSExample.js Fix 16 linter warnings in Examples/ 2015-10-16 04:03:23 -07:00
ActionSheetIOSExample.js Add tintColor for buttons. 2015-12-09 05:19:25 -08:00
ActivityIndicatorIOSExample.js [Flow] Properly fix new errors as of Flow v0.10. 2015-04-27 14:56:21 -08:00
AdSupportIOSExample.js [ReactNative] expose missing haste modules through 'react-native' node module 2015-06-30 18:57:26 -08:00
AlertExample.js Simplified AlertIOS 2016-01-21 10:57:26 -08:00
AlertIOSExample.js Simplified AlertIOS 2016-01-21 10:57:26 -08:00
AnimatedExample.js Fix all warnings for missing keys. 2015-12-11 21:23:29 -08:00
AppStateExample.js Android AppState 2016-01-21 11:47:21 -08:00
AppStateIOSExample.js Fix 16 linter warnings in Examples/ 2015-10-16 04:03:23 -07:00
AssetScaledImageExample.js [Image] Improved loading of Assets Library and Photos Framework images. 2015-07-21 05:32:48 -08:00
AsyncStorageExample.js Fix all warnings for missing keys. 2015-12-11 21:23:29 -08:00
BorderExample.js Added support for corner radii in Android 2016-02-08 10:43:35 -08:00
BoxShadowExample.js Improved shadow performance 2016-01-14 14:04:34 -08:00
CameraRollExample.js Open sourced Camera Roll module 2016-01-14 04:33:11 -08:00
CameraRollView.js Open sourced Camera Roll module 2016-01-14 04:33:11 -08:00
ClipboardExample.js Change the js signature to be Promise based and dynamically detect it used as a callback 2016-01-21 09:49:34 -08:00
DatePickerAndroidExample.js Open source Android date and time pickers 2016-01-26 10:31:17 -08:00
DatePickerIOSExample.js [Flow] Fix or suppress errors in react-native for Flow v0.13.0 2015-06-22 09:48:15 -08:00
ExampleTypes.js Deploy v0.21.0 2016-02-01 17:13:35 -08:00
GeolocationExample.js Fix errors uncovered by v0.19.0 2015-12-01 20:11:26 -08:00
ImageCapInsetsExample.js Generalized image decoding and resizing logic 2016-01-20 11:11:13 -08:00
ImageEditingExample.js Fix ImageEditor example 2016-01-28 09:43:34 -08:00
ImageExample.js Add defaultSource example 2016-02-01 10:20:35 -08:00
IntentAndroidExample.android.js Open source IntentAndroid 2015-11-12 12:41:32 -08:00
LayoutEventsExample.js Fix errors uncovered by v0.19.0 2015-12-01 20:11:26 -08:00
LayoutExample.js Migrate unit tests from FBReactKitModules to FBReactKit 2015-07-07 16:39:35 -08:00
ListViewExample.js Open source Android date and time pickers 2016-01-26 10:31:17 -08:00
ListViewGridLayoutExample.js Fixed missing rows on UIExplorer <ListView> - Grid Layout example 2016-02-10 08:37:57 -08:00
ListViewPagingExample.js Fixed missing rows on UIExplorer <ListView> - Grid Layout example 2016-02-10 08:37:57 -08:00
MapViewExample.js Add MapView annotation callback when it gets / lost the focus 2016-01-29 06:26:30 -08:00
ModalExample.js Make <Modal> visible by default 2015-10-30 17:09:27 -07:00
NavigatorIOSColorsExample.js Fix one warning 2015-09-30 21:02:25 -07:00
NavigatorIOSExample.js PixelRatio.pixel() 2016-01-15 05:15:31 -08:00
NetInfoExample.js Don't use arrow functions with Flow types to fix website generation 2015-12-09 14:56:40 -08:00
PanResponderExample.js Fix errors uncovered by v0.19.0 2015-12-01 20:11:26 -08:00
PickerAndroidExample.js Add a cross-platform Picker 2016-01-29 03:59:54 -08:00
PickerIOSExample.js Fix PickerIOSExample 2015-12-08 13:48:28 -08:00
PointerEventsExample.js Better text descriptions for examples 2015-09-15 14:55:27 -07:00
ProgressBarAndroidExample.android.js ProgressBarAndroid: default value for styleAttr 2016-01-07 12:02:37 -08:00
ProgressViewIOSExample.js [Flow] Fix or suppress errors in react-native for Flow v0.13.0 2015-06-22 09:48:15 -08:00
PullToRefreshViewAndroidExample.android.js fix lint warnings: white spaces and es6 arrow func 2016-01-09 01:35:31 -08:00
PushNotificationIOSExample.js Updates from Wed 1 Apr 2015-04-01 18:37:03 -07:00
RCTRootViewIOSExample.js RN: Revamp YellowBox for Warnings 2015-11-20 13:09:16 -08:00
README.md Add git clone step to READMEs 2015-11-16 22:55:45 -05:00
RefreshControlExample.js Open source Android date and time pickers 2016-01-26 10:31:17 -08:00
ScrollViewExample.js Replace `ScrollView.scrollTo()` API with something less ambiguous. 2016-02-03 04:00:40 -08:00
ScrollViewSimpleExample.js Get back 100% in sync with fb codebase 2015-09-16 10:30:53 -07:00
SegmentedControlIOSExample.js Update SegmentedControlIOSExample.js 2015-07-08 12:52:04 -08:00
SetPropertiesExampleApp.js 'Update app properties in runtime' UIExplorer demo 2015-11-12 11:43:34 -08:00
SliderIOSExample.js Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
StatusBarExample.js Cross platform status bar API 2016-02-03 06:41:35 -08:00
StatusBarIOSExample.js Fix all warnings for missing keys. 2015-12-11 21:23:29 -08:00
SwitchExample.js Update examples for the converged Switch component 2016-01-11 12:46:50 -08:00
TabBarIOSExample.js Managed assets support for RCTConvert 2015-09-29 09:21:39 -07:00
TextExample.android.js Add <Text> shadow support 2016-01-01 09:33:31 -08:00
TextExample.ios.js Added support for width & height for text images 2016-01-22 11:32:32 -08:00
TextInputExample.android.js added accessibility props for touchables 2016-02-04 05:13:32 -08:00
TextInputExample.ios.js added accessibility props for touchables 2016-02-04 05:13:32 -08:00
TimePickerAndroidExample.js Open source Android date and time pickers 2016-01-26 10:31:17 -08:00
TimerExample.js Fix all warnings for missing keys. 2015-12-11 21:23:29 -08:00
ToastAndroidExample.android.js Fix typos in example descriptions. 2015-10-20 04:38:21 -07:00
ToolbarAndroidExample.android.js Allow for styling of ToolbarAndroid's overflow icon 2015-10-22 04:43:25 -07:00
TouchableExample.js added accessibility props for touchables 2016-02-04 05:13:32 -08:00
TransformExample.js Added JS wrappers for ImageStore and ImageEditor 2015-12-23 10:08:07 -08:00
TransparentHitTestExample.js Hit testing now treats views with 0.0 opacity as interactable 2015-10-30 04:14:25 -07:00
UIExplorerApp.android.js Navigation Back support and examples for Android 2016-02-08 20:03:31 -08:00
UIExplorerApp.ios.js Cross platform status bar API 2016-02-03 06:41:35 -08:00
UIExplorerBlock.js Fixed text background color 2015-05-28 09:31:57 -08:00
UIExplorerButton.js Add Timer example 2015-09-11 02:00:31 -07:00
UIExplorerList.android.js Navigation Back support and examples for Android 2016-02-08 20:03:31 -08:00
UIExplorerList.ios.js NavigationExperimental 2016-02-05 14:26:35 -08:00
UIExplorerListBase.js PixelRatio.pixel() 2016-01-15 05:15:31 -08:00
UIExplorerPage.js [React Native] Fix padding in UIExplorer 2015-07-03 02:24:56 -08:00
UIExplorerTitle.js [React Native] Fix padding in UIExplorer 2015-07-03 02:24:56 -08:00
VibrationIOSExample.js [React Native] Sync from github 2015-03-27 22:09:11 -08:00
ViewExample.js Support dashed and dotted border styles on iOS 2015-12-23 10:07:28 -08:00
ViewPagerAndroidExample.android.js Add onPageScrollStateChanged for ViewPagerAndroid 2016-01-29 01:17:35 -08:00
WebViewExample.js Support non-image assets in packager 2016-02-03 17:30:39 -08:00
XHRExample.android.js PixelRatio.pixel() 2016-01-15 05:15:31 -08:00
XHRExample.ios.js PixelRatio.pixel() 2016-01-15 05:15:31 -08:00
XHRExampleCookies.js Support cookies on Android 2015-11-23 03:21:31 -08:00
XHRExampleFetch.js Get response url from XMLHttpRequest 2016-01-07 12:03:48 -08:00
XHRExampleHeaders.js Fix errors uncovered by v0.19.0 2015-12-01 20:11:26 -08:00
bunny.png add remote image support to toolbar 2015-09-30 09:21:27 -07:00
createExamplePage.js Fix duplicate platform labels in UIExplorer examples 2016-01-28 04:07:34 -08:00
flux@3x.png Managed assets support for RCTConvert 2015-09-29 09:21:39 -07:00
hawk.png add remote image support to toolbar 2015-09-30 09:21:27 -07:00
helloworld.html Support non-image assets in packager 2016-02-03 17:30:39 -08:00
slider-left.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
slider-left@2x.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
slider-right.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
slider-right@2x.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
slider.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
slider@2x.png Add option for both min/max track image. 2015-12-21 10:30:39 -08:00
uie_comment_highlighted@2x.png Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00
uie_comment_normal@2x.png Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00
uie_thumb_big.png added method to set thumb image 2015-11-24 16:10:04 -08:00
uie_thumb_normal@2x.png Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00
uie_thumb_selected@2x.png Update Image docs and examples to the new asset system 2016-01-27 13:47:45 -08:00

README.md

UIExplorer

The UIExplorer is a sample app that showcases React Native views and modules.

Running this app

Before running the app, make sure you ran:

git clone https://github.com/facebook/react-native.git
cd react-native
npm install

Running on iOS

Mac OS and Xcode are required.

  • Open Examples/UIExplorer/UIExplorer.xcodeproj in Xcode
  • Hit the Run button

See Running on device if you want to use a physical device.

Running on Android

You'll need to have all the prerequisites (SDK, NDK) for Building React Native installed.

Start an Android emulator (Genymotion is recommended).

cd react-native
./gradlew :Examples:UIExplorer:android:app:installDebug
./packager/packager.sh

Note: Building for the first time can take a while.

Open the UIExplorer app in your emulator.

See Running on Device in case you want to use a physical device.

Built from source

Building the app on both iOS and Android means building the React Native framework from source. This way you're running the latest native and JS code the way you see it in your clone of the github repo.

This is different from apps created using react-native init which have a dependency on a specific version of React Native JS and native code, declared in a package.json file (and build.gradle for Android apps).