0 / 0 / 0
Регистрация: 13.12.2017
Сообщений: 32
1

ReactNative.GridView

02.04.2018, 22:39. Показов 562. Ответов 0
Метки нет (Все метки)

Author24 — интернет-сервис помощи студентам
Всем Привет!
Новичок в реакте.Балуюсь с flickr api.
Не получаеться решить проблему с сеткой .сделал пока произвольный slider на первом экране в котором задаю параметры для grid на втором экране(до 5 фоток в ряд).Не могу понять как можно правильно настроить сетку и слайдер.

Экран поиска
Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
import React, { Component } from 'react';
import {
    StyleSheet,
    Text,
    TextInput,
    View,
    Slider,
    ActivityIndicator,
    ListView,
    TouchableHighlight
} from 'react-native';
import { executeFetchRequest, urlForSearchtext, urlForInteresting } from '../DataManager';
const ResultsScreen = require('./ResultsScreen');
const DetailScreen = require('./DetailScreen');
 
 
class SearchScreen extends Component {
    constructor(props) {
        super(props);
        const dataSource = new ListView.DataSource(
            {rowHasChanged: (r1,r2) => r1.id !== r2.id }
        );
        this.state = {
            searchText: 'Summer',
            isLoading: false,
            dataSource: dataSource.cloneWithRows([]),
            photos: []
        };
    }
 
    // Event handlers
    _onPressSearch() {
        const url = urlForSearchtext(this.state.searchText);
        this.setState({ isLoading: true });
        executeFetchRequest(url, (photos) => {
            this.setState({ isLoading: false });
            this.props.navigator.push ({
                title: this.state.searchText + ' Photos',
                component: ResultsScreen,
                passProps: {photos: photos}
            });
        });
    }
 
 
    // Lifecycle
    componentDidMount() {
        const url = urlForInteresting();
        executeFetchRequest(url, (photos) => {
            let dataSource = new ListView.DataSource(
                {rowHasChanged: (r1,r2) => r1.id !== r2.id }
            );
            this.setState({
                isLoading: false,
                dataSource: dataSource.cloneWithRows(photos),
                photos: photos
            });
        });
    }
 
    render() {
        const spinner = this.state.isLoading ? (<ActivityIndicator size='large'/>) : (<View/>);
        return (
            <View style={styles.root}>
                <View style={styles.topContainer}>
                    <Text style={styles.screenTitle}>Search</Text>
                    <TextInput style={styles.textInput}
                        placeholder='"Anything"'
                        onChangeText={(searchText) => this.setState({searchText})}
                    />
                    {spinner}
                    <TouchableHighlight style={styles.searchButton}
                        onPress={this._onPressSearch.bind(this)}
                        underlayColor='#007AFF'>
                        <Text style={styles.buttonText}>GO</Text>
                    </TouchableHighlight>
 
                </View>
                <View style={styles.bottomContainer}>
                    <Slider
                        style={{ width: 300 }}
                        step={1}
                        minimumValue={1}
                        maximumValue={5}
                        value={this.state.column}
                        onValueChange={val => this.setState({ column: val })}
                    />
                    <Text style={styles.welcome}>
                        {this.state.column}
                    </Text>
 
                </View>
            </View>
        );
    }
}
 
 
// Styles
const styles = StyleSheet.create({
    root: {
        flex: 1,
        alignItems: 'center' ,
    },
    topContainer: {
        margin: 10,
        borderRadius: 10,
        flex: 2,
        alignSelf: 'stretch',
        justifyContent: 'center',
        marginBottom: 20
    },
    screenTitle: {
        fontSize: 50,
        fontFamily: 'helvetica',
        fontWeight: 'bold',
        alignSelf: 'center',
        textAlign: 'center',
        color: '#4A4A4A',
    },
    textInput: {
        fontSize: 30,
        fontFamily: 'helvetica',
        fontWeight: 'bold',
        alignSelf: 'center',
        textAlign: 'center',
        color: '#007AFF',
        marginTop: 30,
        height: 64, width: 300
    },
    searchButton: {
        marginTop: 20,
        alignSelf: 'center',
        justifyContent: 'center',
        backgroundColor: '#007AFF',
        borderRadius: 20,
        height: 64, width: 64
    },
    buttonText: {
        fontSize: 24,
        fontFamily: 'helvetica',
        fontWeight: 'bold',
        color: '#FFF',
        textAlign: 'center',
    },
    bottomContainer: {
        flex: 2,
        paddingRight: 10
    },
    listContainer: {
        flex: 1
    },
    rowContainer: {
        flex: 5,
        backgroundColor:'transparent',
        paddingLeft: 10, paddingTop: 10, paddingBottom: 10
    },
 
    welcome: {
        fontSize: 20,
        textAlign: 'center',
        margin: 10,
    },
    instructions: {
        textAlign: 'center',
        color: '#333333',
        marginBottom: 5,
    },
})
 
module.exports = SearchScreen;
Страница уже с картинками


Javascript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import React, { Component } from 'react';
import {
    StyleSheet,
    Image,
    View,
    TouchableHighlight,
    ListView,
    Text
} from 'react-native';
const DetailScreen = require('./DetailScreen');
 
 
class ResultsScreen extends Component {
    constructor(props) {
        super(props);
        const dataSource = new ListView.DataSource(
            {rowHasChanged: (r1,r2) => r1.id !== r2.id }
 
        );
        this.state = {
            dataSource: dataSource.cloneWithRows(this.props.photos)
        };
    }
 
 
    _rowPressed(selectedPhoto) {
        const photo = this.props.photos.filter(photo => photo === selectedPhoto)[0]
        this.props.navigator.push({
            title: photo.title,
            component: DetailScreen,
            passProps: { photo: photo }
        });
    }
 
 
    _renderRow(rowData, sectionID, rowID) {
        return (
            <TouchableHighlight underlayColor='transparent'
            onPress={() => this._rowPressed(rowData)}>
                <View style={styles.rowContainer}>
                    <Image style={styles.image}
                        source={{ uri: rowData.url_m }}>
                    </Image>
                </View>
            </TouchableHighlight>
        );
    }
    render() {
        return (
            <View style={styles.root}>
                <ListView
                    dataSource={this.state.dataSource}
                    renderRow={this._renderRow.bind(this)}
                    enableEmptySections={true}
                />
            </View>
        );
    }
}
 
 
const styles = StyleSheet.create({
    root: {
        paddingBottom: 5
    },
    rowContainer: {
        backgroundColor:'transparent',
        paddingTop: 20, paddingLeft: 120, paddingRight: 10,
 
    },
    image: {
        flex: 1,
        height: 162,width:162,
        borderRadius: 10
    },
 
});
 
module.exports = ResultsScreen;
0
Programming
Эксперт
94731 / 64177 / 26122
Регистрация: 12.04.2006
Сообщений: 116,782
02.04.2018, 22:39
Ответы с готовыми решениями:

Обновление информации в GridView при клике в другом GridView
Здравствуйте! Интересует возможность смена информации в одном GirdView2 посредством выборки...

Как разворачивать поле у GridView (вложенный gridview)
Мне нужно выводить в GridView часть данных одной таблице, а оставшуюся часть данных прятать в полях...

Значение из одной ячейки gridView на одной странице добавить в gridView на другой
Нужно значение из одной ячейки gridView на одной странице добавить в gridView на другой.. (через...

GridView
я уже писал этот вопрос, но перепутал раздел. подскажите пожалуйста. У меня есть GridView с...

0
02.04.2018, 22:39
IT_Exp
Эксперт
87844 / 49110 / 22898
Регистрация: 17.06.2006
Сообщений: 92,604
02.04.2018, 22:39
Помогаю со студенческими работами здесь

GridView
Собственно вопрос такой: есть база данных, через которую мы заполняем дерево. Нужно реализовать...

GridView
Здравствуйте, подскажите где посмотреть пример для прокрутки грида в горизонтальном направлении,...

GridView
Привет. Есть GridView в котором находяться разные элементы! Один из них HyperLink, как можно узнать...

GridView и БД
Подскажите пожалуйста, как запихать в GridView не всю таблицу, а только последние три записи?


Искать еще темы с ответами

Или воспользуйтесь поиском по форуму:
1
Ответ Создать тему
Опции темы

КиберФорум - форум программистов, компьютерный форум, программирование
Powered by vBulletin
Copyright ©2000 - 2024, CyberForum.ru