2015-02-20 04:10:52 +00:00
|
|
|
/**
|
2015-03-28 05:18:47 +00:00
|
|
|
* The examples provided by Facebook are for non-commercial testing and
|
|
|
|
* evaluation purposes only.
|
2015-03-23 20:35:08 +00:00
|
|
|
*
|
2015-03-28 05:18:47 +00:00
|
|
|
* Facebook reserves all rights not expressly granted.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* FACEBOOK BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2015-03-23 20:35:08 +00:00
|
|
|
*
|
2015-04-27 22:18:37 +00:00
|
|
|
* @flow
|
2015-02-20 04:10:52 +00:00
|
|
|
*/
|
|
|
|
'use strict';
|
|
|
|
|
2015-03-23 03:32:49 +00:00
|
|
|
var React = require('react-native');
|
2015-02-20 04:10:52 +00:00
|
|
|
var {
|
2015-03-25 05:07:16 +00:00
|
|
|
AppRegistry,
|
2015-03-19 01:16:09 +00:00
|
|
|
ListView,
|
2015-02-20 04:10:52 +00:00
|
|
|
PixelRatio,
|
|
|
|
StyleSheet,
|
|
|
|
Text,
|
2015-03-19 18:05:24 +00:00
|
|
|
TextInput,
|
2015-02-20 04:10:52 +00:00
|
|
|
TouchableHighlight,
|
|
|
|
View,
|
|
|
|
} = React;
|
|
|
|
|
2015-03-25 05:07:16 +00:00
|
|
|
var { TestModule } = React.addons;
|
2015-05-05 12:34:39 +00:00
|
|
|
var Settings = require('Settings');
|
2015-03-25 05:07:16 +00:00
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
import type { Example, ExampleModule } from 'ExampleTypes';
|
|
|
|
|
2015-02-20 04:10:52 +00:00
|
|
|
var createExamplePage = require('./createExamplePage');
|
|
|
|
|
2015-03-19 01:16:09 +00:00
|
|
|
var COMPONENTS = [
|
2015-04-01 03:26:29 +00:00
|
|
|
require('./ActivityIndicatorIOSExample'),
|
|
|
|
require('./DatePickerIOSExample'),
|
2015-02-20 04:10:52 +00:00
|
|
|
require('./ImageExample'),
|
2015-04-01 03:26:29 +00:00
|
|
|
require('./ListViewExample'),
|
2015-02-20 04:10:52 +00:00
|
|
|
require('./ListViewPagingExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./MapViewExample'),
|
2015-04-23 13:22:16 +00:00
|
|
|
require('./Navigator/NavigatorExample'),
|
|
|
|
require('./NavigatorIOSColorsExample'),
|
2015-04-13 11:12:45 +00:00
|
|
|
require('./NavigatorIOSExample'),
|
2015-04-01 03:26:29 +00:00
|
|
|
require('./PickerIOSExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./ScrollViewExample'),
|
Add SegmentedControlIOS
Summary:
Fixes #534:
![screen shot 2015-03-31 at 7 52 10 pm](https://cloud.githubusercontent.com/assets/153704/6934038/742ddd34-d7e3-11e4-8f55-3eb7d9d3f1cd.png)
```jsx
<SegmentedControlIOS
tintColor="#ff0000"
values={['One', 'Two', 'Three', 'Four']}
selectedtIndex={0}
momentary={false}
enabled={true}
onValueChange={ (value) => console.log(value) } />
```
This only supports string-based segments, not images. Also doesn't support full customization (no separator images etc); I figure this is a good MVP to lock-down a basic API
I also included a snapshot test case, but the images keep coming out funky. When I look at the sim, I see that the text labels show up for the selected segment, but the snapshot keeps coming out with no text on those segments. I tried forcing a delay, but same result. Is that explainable?
Obviously happy to change anything about the API, code-style nitpicks, etc
Closes https://github.com/facebook/react-native/pull/564
Github Author: Clay Allsopp <clay.allsopp@gmail.com>
Test Plan: Imported from GitHub, without a `Test Plan:` line.
2015-04-29 15:15:28 +00:00
|
|
|
require('./SegmentedControlIOSExample'),
|
2015-03-18 15:56:49 +00:00
|
|
|
require('./SliderIOSExample'),
|
2015-04-01 03:26:29 +00:00
|
|
|
require('./SwitchIOSExample'),
|
|
|
|
require('./TabBarIOSExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./TextExample.ios'),
|
|
|
|
require('./TextInputExample'),
|
|
|
|
require('./TouchableExample'),
|
|
|
|
require('./ViewExample'),
|
2015-03-14 08:22:25 +00:00
|
|
|
require('./WebViewExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
var APIS = [
|
2015-05-28 10:56:48 +00:00
|
|
|
require('./AccessibilityIOSExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./ActionSheetIOSExample'),
|
2015-03-10 19:09:35 +00:00
|
|
|
require('./AdSupportIOSExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./AlertIOSExample'),
|
|
|
|
require('./AppStateIOSExample'),
|
|
|
|
require('./AsyncStorageExample'),
|
2015-03-26 08:43:17 +00:00
|
|
|
require('./BorderExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./CameraRollExample.ios'),
|
|
|
|
require('./GeolocationExample'),
|
[ReactNative] Introduce onLayout events
Summary:
Simply add an `onLayout` callback to a native view component, and the callback
will be invoked with the current layout information when the view is mounted and
whenever the layout changes.
The only limitation is that scroll position and other stuff the layout system
isn't aware of is not taken into account. This is because onLayout events
wouldn't be triggered for these changes and if they are desired they should be
tracked separately (e.g. with `onScroll`) and combined.
Also fixes some bugs with LayoutAnimation callbacks.
@public
Test Plan:
- Run new LayoutEventsExample in UIExplorer and see it work correctly.
- New integration test passes internally (IntegrationTest project seems busted).
- New jest test case passes.
{F22318433}
```
2015-05-06 15:45:05.848 [info][tid:com.facebook.React.JavaScript] "Running application "UIExplorerApp" with appParams: {"rootTag":1,"initialProps":{}}. __DEV__ === true, development-level warning are ON, performance optimizations are OFF"
2015-05-06 15:45:05.881 [info][tid:com.facebook.React.JavaScript] "received text layout event
", {"target":27,"layout":{"y":123,"x":12.5,"width":140.5,"height":18}}
2015-05-06 15:45:05.882 [info][tid:com.facebook.React.JavaScript] "received image layout event
", {"target":23,"layout":{"y":12.5,"x":122,"width":50,"height":50}}
2015-05-06 15:45:05.883 [info][tid:com.facebook.React.JavaScript] "received view layout event
", {"target":22,"layout":{"y":70.5,"x":20,"width":294,"height":204}}
2015-05-06 15:45:05.897 [info][tid:com.facebook.React.JavaScript] "received text layout event
", {"target":27,"layout":{"y":206.5,"x":12.5,"width":140.5,"height":18}}
2015-05-06 15:45:05.897 [info][tid:com.facebook.React.JavaScript] "received view layout event
", {"target":22,"layout":{"y":70.5,"x":20,"width":294,"height":287.5}}
2015-05-06 15:45:09.847 [info][tid:com.facebook.React.JavaScript] "layout animation done."
2015-05-06 15:45:09.847 [info][tid:com.facebook.React.JavaScript] "received image layout event
", {"target":23,"layout":{"y":12.5,"x":82,"width":50,"height":50}}
2015-05-06 15:45:09.848 [info][tid:com.facebook.React.JavaScript] "received view layout event
", {"target":22,"layout":{"y":110.5,"x":60,"width":214,"height":287.5}}
2015-05-06 15:45:09.862 [info][tid:com.facebook.React.JavaScript] "received text layout event
", {"target":27,"layout":{"y":206.5,"x":12.5,"width":120,"height":68}}
2015-05-06 15:45:09.863 [info][tid:com.facebook.React.JavaScript] "received image layout event
", {"target":23,"layout":{"y":12.5,"x":55,"width":50,"height":50}}
2015-05-06 15:45:09.863 [info][tid:com.facebook.React.JavaScript] "received view layout event
", {"target":22,"layout":{"y":128,"x":60,"width":160,"height":337.5}}
```
2015-05-07 19:11:02 +00:00
|
|
|
require('./LayoutEventsExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./LayoutExample'),
|
|
|
|
require('./NetInfoExample'),
|
2015-04-13 11:12:45 +00:00
|
|
|
require('./PanResponderExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./PointerEventsExample'),
|
2015-03-24 12:31:11 +00:00
|
|
|
require('./PushNotificationIOSExample'),
|
2015-03-19 01:16:09 +00:00
|
|
|
require('./StatusBarIOSExample'),
|
|
|
|
require('./TimerExample'),
|
2015-03-17 04:02:57 +00:00
|
|
|
require('./VibrationIOSExample'),
|
2015-02-20 04:10:52 +00:00
|
|
|
];
|
|
|
|
|
2015-03-19 18:05:24 +00:00
|
|
|
var ds = new ListView.DataSource({
|
|
|
|
rowHasChanged: (r1, r2) => r1 !== r2,
|
|
|
|
sectionHeaderHasChanged: (h1, h2) => h1 !== h2,
|
|
|
|
});
|
2015-03-19 01:16:09 +00:00
|
|
|
|
2015-03-25 05:07:16 +00:00
|
|
|
function makeRenderable(example: any): ReactClass<any, any, any> {
|
|
|
|
return example.examples ?
|
|
|
|
createExamplePage(null, example) :
|
|
|
|
example;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Register suitable examples for snapshot tests
|
|
|
|
COMPONENTS.concat(APIS).forEach((Example) => {
|
|
|
|
if (Example.displayName) {
|
|
|
|
var Snapshotter = React.createClass({
|
|
|
|
componentDidMount: function() {
|
|
|
|
// View is still blank after first RAF :\
|
|
|
|
global.requestAnimationFrame(() =>
|
|
|
|
global.requestAnimationFrame(() => TestModule.verifySnapshot(
|
|
|
|
TestModule.markTestCompleted
|
|
|
|
)
|
|
|
|
));
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var Renderable = makeRenderable(Example);
|
|
|
|
return <Renderable />;
|
|
|
|
},
|
|
|
|
});
|
|
|
|
AppRegistry.registerComponent(Example.displayName, () => Snapshotter);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
type Props = {
|
|
|
|
navigator: Array<{title: string, component: ReactClass<any,any,any>}>,
|
|
|
|
onExternalExampleRequested: Function,
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
2015-03-19 18:05:24 +00:00
|
|
|
class UIExplorerList extends React.Component {
|
2015-05-12 21:22:22 +00:00
|
|
|
props: Props;
|
2015-03-19 18:05:24 +00:00
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
constructor(props: Props) {
|
2015-03-19 18:05:24 +00:00
|
|
|
super(props);
|
|
|
|
this.state = {
|
2015-03-19 01:16:09 +00:00
|
|
|
dataSource: ds.cloneWithRowsAndSections({
|
|
|
|
components: COMPONENTS,
|
|
|
|
apis: APIS,
|
|
|
|
}),
|
2015-05-05 12:34:39 +00:00
|
|
|
searchText: Settings.get('searchText'),
|
2015-03-19 01:16:09 +00:00
|
|
|
};
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
2015-03-19 01:16:09 +00:00
|
|
|
|
2015-05-05 12:34:39 +00:00
|
|
|
componentDidMount() {
|
|
|
|
this._search(this.state.searchText);
|
|
|
|
}
|
|
|
|
|
2015-03-19 18:05:24 +00:00
|
|
|
render() {
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
2015-03-19 18:05:24 +00:00
|
|
|
<View style={styles.listContainer}>
|
|
|
|
<View style={styles.searchRow}>
|
|
|
|
<TextInput
|
|
|
|
autoCapitalize="none"
|
|
|
|
autoCorrect={false}
|
|
|
|
clearButtonMode="always"
|
|
|
|
onChangeText={this._search.bind(this)}
|
|
|
|
placeholder="Search..."
|
|
|
|
style={styles.searchTextInput}
|
2015-05-05 12:34:39 +00:00
|
|
|
value={this.state.searchText}
|
2015-03-19 18:05:24 +00:00
|
|
|
/>
|
|
|
|
</View>
|
|
|
|
<ListView
|
|
|
|
style={styles.list}
|
|
|
|
dataSource={this.state.dataSource}
|
|
|
|
renderRow={this._renderRow.bind(this)}
|
|
|
|
renderSectionHeader={this._renderSectionHeader}
|
|
|
|
automaticallyAdjustContentInsets={false}
|
|
|
|
/>
|
|
|
|
</View>
|
2015-03-19 01:16:09 +00:00
|
|
|
);
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
2015-03-19 01:16:09 +00:00
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
_renderSectionHeader(data: any, section: string) {
|
2015-03-19 01:16:09 +00:00
|
|
|
return (
|
|
|
|
<View style={styles.sectionHeader}>
|
|
|
|
<Text style={styles.sectionHeaderTitle}>
|
|
|
|
{section.toUpperCase()}
|
|
|
|
</Text>
|
|
|
|
</View>
|
2015-02-20 04:10:52 +00:00
|
|
|
);
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
_renderRow(example: ExampleModule, i: number) {
|
2015-02-20 04:10:52 +00:00
|
|
|
return (
|
|
|
|
<View key={i}>
|
|
|
|
<TouchableHighlight onPress={() => this._onPressRow(example)}>
|
|
|
|
<View style={styles.row}>
|
|
|
|
<Text style={styles.rowTitleText}>
|
|
|
|
{example.title}
|
|
|
|
</Text>
|
|
|
|
<Text style={styles.rowDetailText}>
|
|
|
|
{example.description}
|
|
|
|
</Text>
|
|
|
|
</View>
|
|
|
|
</TouchableHighlight>
|
|
|
|
<View style={styles.separator} />
|
|
|
|
</View>
|
|
|
|
);
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
_search(text: mixed) {
|
2015-03-19 18:05:24 +00:00
|
|
|
var regex = new RegExp(text, 'i');
|
|
|
|
var filter = (component) => regex.test(component.title);
|
2015-02-20 04:10:52 +00:00
|
|
|
|
2015-03-19 18:05:24 +00:00
|
|
|
this.setState({
|
|
|
|
dataSource: ds.cloneWithRowsAndSections({
|
|
|
|
components: COMPONENTS.filter(filter),
|
|
|
|
apis: APIS.filter(filter),
|
2015-05-05 12:34:39 +00:00
|
|
|
}),
|
|
|
|
searchText: text,
|
2015-03-19 18:05:24 +00:00
|
|
|
});
|
2015-05-05 12:34:39 +00:00
|
|
|
Settings.set({searchText: text});
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
|
|
|
|
2015-05-12 21:22:22 +00:00
|
|
|
_onPressRow(example: ExampleModule) {
|
2015-04-23 13:22:16 +00:00
|
|
|
if (example.external) {
|
|
|
|
this.props.onExternalExampleRequested(example);
|
2015-03-24 16:55:38 +00:00
|
|
|
return;
|
|
|
|
}
|
2015-03-25 05:07:16 +00:00
|
|
|
var Component = makeRenderable(example);
|
2015-02-20 04:10:52 +00:00
|
|
|
this.props.navigator.push({
|
|
|
|
title: Component.title,
|
|
|
|
component: Component,
|
|
|
|
});
|
2015-03-19 18:05:24 +00:00
|
|
|
}
|
|
|
|
}
|
2015-02-20 04:10:52 +00:00
|
|
|
|
|
|
|
var styles = StyleSheet.create({
|
2015-03-19 18:05:24 +00:00
|
|
|
listContainer: {
|
|
|
|
flex: 1,
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
list: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
},
|
2015-03-19 01:16:09 +00:00
|
|
|
sectionHeader: {
|
|
|
|
padding: 5,
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
2015-03-19 18:05:24 +00:00
|
|
|
group: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
},
|
2015-03-19 01:16:09 +00:00
|
|
|
sectionHeaderTitle: {
|
2015-03-25 23:22:59 +00:00
|
|
|
fontWeight: '500',
|
2015-03-19 01:16:09 +00:00
|
|
|
fontSize: 11,
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
row: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
justifyContent: 'center',
|
|
|
|
paddingHorizontal: 15,
|
|
|
|
paddingVertical: 8,
|
|
|
|
},
|
|
|
|
separator: {
|
|
|
|
height: 1 / PixelRatio.get(),
|
|
|
|
backgroundColor: '#bbbbbb',
|
|
|
|
marginLeft: 15,
|
|
|
|
},
|
|
|
|
rowTitleText: {
|
|
|
|
fontSize: 17,
|
2015-03-25 23:22:59 +00:00
|
|
|
fontWeight: '500',
|
2015-02-20 04:10:52 +00:00
|
|
|
},
|
|
|
|
rowDetailText: {
|
|
|
|
fontSize: 15,
|
|
|
|
color: '#888888',
|
|
|
|
lineHeight: 20,
|
|
|
|
},
|
2015-03-19 18:05:24 +00:00
|
|
|
searchRow: {
|
|
|
|
backgroundColor: '#eeeeee',
|
|
|
|
paddingTop: 75,
|
|
|
|
paddingLeft: 10,
|
|
|
|
paddingRight: 10,
|
|
|
|
paddingBottom: 10,
|
|
|
|
},
|
|
|
|
searchTextInput: {
|
|
|
|
backgroundColor: 'white',
|
|
|
|
borderColor: '#cccccc',
|
|
|
|
borderRadius: 3,
|
|
|
|
borderWidth: 1,
|
|
|
|
height: 30,
|
|
|
|
paddingLeft: 8,
|
|
|
|
},
|
2015-02-20 04:10:52 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = UIExplorerList;
|