react-native/RNTester/js/RNTesterList.ios.js

399 lines
8.4 KiB
JavaScript
Raw Normal View History

/**
* Copyright (c) 2015-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
* @flow
* @providesModule RNTesterList
*/
'use strict';
export type RNTesterExample = {
Listen to device orientation changes Summary: Similar to iOS, send device orientation changes events. This does not have the `getCurrentOrientation` method, because it's not used. If necessary, we'll add it separately. This also adds a simple example for testing. We listen to orientation changes in `onGlobalLayout`, and check if the rotation of the device has changed. If it has, we emit the event. But: - `onGlobalLayout` (and `onConfigurationChanged` - which is the method usually used for checking for device orientation changes) is *not* called when the device goes from landscape to reverse landscape (same with portrait), as that is not a relayout / configuration change. We could detect if this happens with the help of an `OrientationEventListener`. However, this listener notifies you if the degree of the phone changes by a single degree, which means that you need to know by how many degrees the phone needs to change in order for the orientation to change. I haven't looked into how accurate this could be, but I suspect that in practice it would cause a lot of bugs. A simple `abgs` and google search reveals that everybody uses a different margin for detecting a rotation change (from 30 to 45 degrees), so I suspect that this won't work as expected in practice. Therefore, we're not using this here, and we're sticking to what android provides via `onConfigurationChanged`. If we find that we have issues because users need to know when the user goes from landscape to reverse landscape, then we'll have to revisit this. Reviewed By: foghina Differential Revision: D3797521 fbshipit-source-id: 62508efd342a9a4b41b42b6138c73553cfdefebc
2016-09-06 10:54:27 +00:00
key: string,
module: Object,
supportsTVOS: boolean
};
const ComponentExamples: Array<RNTesterExample> = [
{
key: 'ActivityIndicatorExample',
module: require('./ActivityIndicatorExample'),
supportsTVOS: true,
},
{
key: 'ARTExample',
module: require('./ARTExample'),
supportsTVOS: true,
},
{
key: 'ButtonExample',
module: require('./ButtonExample'),
supportsTVOS: true,
},
{
key: 'DatePickerIOSExample',
module: require('./DatePickerIOSExample'),
supportsTVOS: false,
},
{
key: 'FlatListExample',
module: require('./FlatListExample'),
supportsTVOS: true,
},
{
key: 'ImageExample',
module: require('./ImageExample'),
supportsTVOS: true,
},
{
key: 'KeyboardAvoidingViewExample',
module: require('./KeyboardAvoidingViewExample'),
supportsTVOS: false,
},
{
key: 'LayoutEventsExample',
module: require('./LayoutEventsExample'),
supportsTVOS: true,
},
{
key: 'ListViewExample',
module: require('./ListViewExample'),
supportsTVOS: true,
},
{
key: 'ListViewGridLayoutExample',
module: require('./ListViewGridLayoutExample'),
supportsTVOS: true,
},
{
key: 'ListViewPagingExample',
module: require('./ListViewPagingExample'),
supportsTVOS: true,
},
MaskedViewIOS -- A way to apply alpha masks to views on iOS Summary: It's very important in complex UIs to be able to apply alpha channel-based masks to arbitrary content. Common use cases include adding gradient masks at the top or bottom of scroll views, creating masked text effects, feathering images, and generally just masking views while still allowing transparency of those views. The original motivation for creating this component stemmed from work on `react-navigation`. As I tried to mimic behavior in the native iOS header, I needed to be able to achieve the effect pictured here (this is a screenshot from a native iOS application): ![iOS native navbar animation](https://slack-imgs.com/?c=1&url=https%3A%2F%2Fd3vv6lp55qjaqc.cloudfront.net%2Fitems%2F0N3g1Q3H423P3m1c1z3E%2FScreen%2520Shot%25202017-07-06%2520at%252011.57.29%2520AM.png) In this image, there are two masks: - A mask on the back button chevron - A gradient mask on the right button In addition, the underlying view in the navigation bar is intended to be a UIBlurView. Thus, alpha masking is the only way to achieve this effect. Behind the scenes, the `maskView` property on `UIView` is used. This is a shortcut to setting the mask on the CALayer directly. This gives us the ability to mask any view with any other view. While building this component (and testing in the context of an Expo app), I was able to use a `GLView` (a view that renders an OpenGL context) to mask a `Video` component! I chose to implement this only on iOS right now, as the Android implementation is a) significantly more complicated and b) will most likely not be as performant (especially when trying to mask more complex views). Review the `<MaskedViewIOS>` section in the RNTester app, observe that views are masked appropriately. ![example](https://d3vv6lp55qjaqc.cloudfront.net/items/250X092v2k3f212f3O16/Screen%20Recording%202017-07-07%20at%2012.18%20PM.gif?X-CloudApp-Visitor-Id=abb33b3e3769bbe2f7b26d13dc5d1442&v=5f9e2d4c) Closes https://github.com/facebook/react-native/pull/14898 Differential Revision: D5398721 Pulled By: javache fbshipit-source-id: 343af874e2d664541aca1fefe922cf7d82aea701
2017-07-11 22:00:54 +00:00
{
key: 'MaskedViewExample',
module: require('./MaskedViewExample'),
supportsTVOS: true,
},
{
key: 'ModalExample',
module: require('./ModalExample'),
supportsTVOS: true,
},
{
key: 'MultiColumnExample',
module: require('./MultiColumnExample'),
supportsTVOS: true,
},
{
key: 'NavigatorIOSColorsExample',
module: require('./NavigatorIOSColorsExample'),
supportsTVOS: false,
},
{
key: 'NavigatorIOSBarStyleExample',
module: require('./NavigatorIOSBarStyleExample'),
supportsTVOS: false,
},
{
key: 'NavigatorIOSExample',
module: require('./NavigatorIOSExample'),
supportsTVOS: true,
},
{
key: 'PickerExample',
module: require('./PickerExample'),
supportsTVOS: false,
},
{
key: 'PickerIOSExample',
module: require('./PickerIOSExample'),
supportsTVOS: false,
},
{
key: 'ProgressViewIOSExample',
module: require('./ProgressViewIOSExample'),
supportsTVOS: true,
},
{
key: 'RefreshControlExample',
module: require('./RefreshControlExample'),
supportsTVOS: false,
},
{
key: 'SafeAreaViewExample',
module: require('./SafeAreaViewExample'),
supportsTVOS: true,
},
{
key: 'ScrollViewExample',
module: require('./ScrollViewExample'),
supportsTVOS: true,
},
{
key: 'SectionListExample',
module: require('./SectionListExample'),
supportsTVOS: true,
},
{
key: 'SegmentedControlIOSExample',
module: require('./SegmentedControlIOSExample'),
supportsTVOS: false,
},
{
key: 'SliderExample',
module: require('./SliderExample'),
supportsTVOS: false,
},
{
key: 'StatusBarExample',
module: require('./StatusBarExample'),
supportsTVOS: false,
},
{
key: 'SwipeableFlatListExample',
module: require('./SwipeableFlatListExample'),
supportsTVOS: false,
},
{
key: 'SwipeableListViewExample',
module: require('./SwipeableListViewExample'),
supportsTVOS: false,
},
{
key: 'SwitchExample',
module: require('./SwitchExample'),
supportsTVOS: false,
},
{
key: 'TabBarIOSExample',
module: require('./TabBarIOSExample'),
supportsTVOS: true,
},
{
key: 'TabBarIOSBarStyleExample',
module: require('./TabBarIOSBarStyleExample'),
supportsTVOS: false,
},
{
key: 'TextExample',
module: require('./TextExample.ios'),
supportsTVOS: true,
},
{
key: 'TextInputExample',
module: require('./TextInputExample.ios'),
supportsTVOS: true,
},
{
key: 'TouchableExample',
module: require('./TouchableExample'),
supportsTVOS: false,
},
{
key: 'TransparentHitTestExample',
module: require('./TransparentHitTestExample'),
supportsTVOS: false,
},
{
key: 'ViewExample',
module: require('./ViewExample'),
supportsTVOS: true,
},
{
key: 'WebViewExample',
module: require('./WebViewExample'),
supportsTVOS: false,
},
];
const APIExamples: Array<RNTesterExample> = [
{
key: 'AccessibilityIOSExample',
module: require('./AccessibilityIOSExample'),
supportsTVOS: false,
},
{
key: 'ActionSheetIOSExample',
module: require('./ActionSheetIOSExample'),
supportsTVOS: true,
},
{
key: 'AlertExample',
module: require('./AlertExample').AlertExample,
supportsTVOS: true,
},
{
key: 'AlertIOSExample',
module: require('./AlertIOSExample'),
supportsTVOS: true,
},
{
key: 'AnimatedExample',
module: require('./AnimatedExample'),
supportsTVOS: true,
},
{
key: 'AnExApp',
module: require('./AnimatedGratuitousApp/AnExApp'),
supportsTVOS: true,
},
{
key: 'AppStateExample',
module: require('./AppStateExample'),
supportsTVOS: true,
},
{
key: 'AsyncStorageExample',
module: require('./AsyncStorageExample'),
supportsTVOS: true,
},
{
key: 'BorderExample',
module: require('./BorderExample'),
supportsTVOS: true,
},
{
key: 'BoxShadowExample',
module: require('./BoxShadowExample'),
supportsTVOS: true,
},
{
key: 'CameraRollExample',
module: require('./CameraRollExample'),
supportsTVOS: false,
},
{
key: 'ClipboardExample',
module: require('./ClipboardExample'),
supportsTVOS: false,
},
{
key: 'Dimensions',
module: require('./DimensionsExample'),
supportsTVOS: true,
},
{
key: 'GeolocationExample',
module: require('./GeolocationExample'),
supportsTVOS: false,
},
{
key: 'ImageEditingExample',
module: require('./ImageEditingExample'),
supportsTVOS: false,
},
{
key: 'LayoutAnimationExample',
module: require('./LayoutAnimationExample'),
supportsTVOS: true,
},
{
key: 'LayoutExample',
module: require('./LayoutExample'),
supportsTVOS: true,
},
{
key: 'LinkingExample',
module: require('./LinkingExample'),
supportsTVOS: true,
},
{
key: 'NativeAnimationsExample',
module: require('./NativeAnimationsExample'),
supportsTVOS: true,
},
{
key: 'NetInfoExample',
module: require('./NetInfoExample'),
supportsTVOS: true,
},
Listen to device orientation changes Summary: Similar to iOS, send device orientation changes events. This does not have the `getCurrentOrientation` method, because it's not used. If necessary, we'll add it separately. This also adds a simple example for testing. We listen to orientation changes in `onGlobalLayout`, and check if the rotation of the device has changed. If it has, we emit the event. But: - `onGlobalLayout` (and `onConfigurationChanged` - which is the method usually used for checking for device orientation changes) is *not* called when the device goes from landscape to reverse landscape (same with portrait), as that is not a relayout / configuration change. We could detect if this happens with the help of an `OrientationEventListener`. However, this listener notifies you if the degree of the phone changes by a single degree, which means that you need to know by how many degrees the phone needs to change in order for the orientation to change. I haven't looked into how accurate this could be, but I suspect that in practice it would cause a lot of bugs. A simple `abgs` and google search reveals that everybody uses a different margin for detecting a rotation change (from 30 to 45 degrees), so I suspect that this won't work as expected in practice. Therefore, we're not using this here, and we're sticking to what android provides via `onConfigurationChanged`. If we find that we have issues because users need to know when the user goes from landscape to reverse landscape, then we'll have to revisit this. Reviewed By: foghina Differential Revision: D3797521 fbshipit-source-id: 62508efd342a9a4b41b42b6138c73553cfdefebc
2016-09-06 10:54:27 +00:00
{
key: 'OrientationChangeExample',
module: require('./OrientationChangeExample'),
supportsTVOS: false,
Listen to device orientation changes Summary: Similar to iOS, send device orientation changes events. This does not have the `getCurrentOrientation` method, because it's not used. If necessary, we'll add it separately. This also adds a simple example for testing. We listen to orientation changes in `onGlobalLayout`, and check if the rotation of the device has changed. If it has, we emit the event. But: - `onGlobalLayout` (and `onConfigurationChanged` - which is the method usually used for checking for device orientation changes) is *not* called when the device goes from landscape to reverse landscape (same with portrait), as that is not a relayout / configuration change. We could detect if this happens with the help of an `OrientationEventListener`. However, this listener notifies you if the degree of the phone changes by a single degree, which means that you need to know by how many degrees the phone needs to change in order for the orientation to change. I haven't looked into how accurate this could be, but I suspect that in practice it would cause a lot of bugs. A simple `abgs` and google search reveals that everybody uses a different margin for detecting a rotation change (from 30 to 45 degrees), so I suspect that this won't work as expected in practice. Therefore, we're not using this here, and we're sticking to what android provides via `onConfigurationChanged`. If we find that we have issues because users need to know when the user goes from landscape to reverse landscape, then we'll have to revisit this. Reviewed By: foghina Differential Revision: D3797521 fbshipit-source-id: 62508efd342a9a4b41b42b6138c73553cfdefebc
2016-09-06 10:54:27 +00:00
},
{
key: 'PanResponderExample',
module: require('./PanResponderExample'),
supportsTVOS: false,
},
{
key: 'PointerEventsExample',
module: require('./PointerEventsExample'),
supportsTVOS: false,
},
{
key: 'PushNotificationIOSExample',
module: require('./PushNotificationIOSExample'),
supportsTVOS: false,
},
{
key: 'RCTRootViewIOSExample',
module: require('./RCTRootViewIOSExample'),
supportsTVOS: true,
},
{
key: 'RTLExample',
module: require('./RTLExample'),
supportsTVOS: true,
},
{
key: 'ShareExample',
module: require('./ShareExample'),
supportsTVOS: true,
},
{
key: 'SnapshotExample',
module: require('./SnapshotExample'),
supportsTVOS: true,
},
{
key: 'TimerExample',
module: require('./TimerExample'),
supportsTVOS: true,
},
{
key: 'TransformExample',
module: require('./TransformExample'),
supportsTVOS: true,
},
{
key: 'TVEventHandlerExample',
module: require('./TVEventHandlerExample'),
supportsTVOS: true,
},
{
key: 'VibrationExample',
module: require('./VibrationExample'),
supportsTVOS: false,
},
{
key: 'WebSocketExample',
module: require('./WebSocketExample'),
supportsTVOS: true,
},
{
key: 'XHRExample',
module: require('./XHRExample'),
supportsTVOS: true,
},
];
const Modules = {};
APIExamples.concat(ComponentExamples).forEach(Example => {
Modules[Example.key] = Example.module;
});
const RNTesterList = {
APIExamples,
ComponentExamples,
Modules,
};
module.exports = RNTesterList;