質問編集履歴

1

スクショの削除

2024/03/20 10:54

投稿

_chii
_chii

スコア50

test CHANGED
File without changes
test CHANGED
@@ -1,8 +1,6 @@
1
1
  ### 実現したいこと
2
2
  当該コードはReact Native ですがロジック自体は関係がないためタイトルをReactにさせて頂きました。
3
3
  現場のコードでは特定の項目のチェックボックス(完了ボタン)をタップしても全ての項目に打ち消し線が引かれてしまう状態ですが、これをタップした項目に適用できるようにしたいです
4
-
5
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2024-03-18/af540755-f970-4fcd-8e89-bac14b289b26.png)
6
4
 
7
5
  ### 発生している問題・分からないこと
8
6
  `onPress={handlePress}` のhandlePressの引数にindexを使用することは理解できます。
@@ -11,123 +9,6 @@
11
9
 
12
10
 
13
11
  ### 該当のソースコード
14
-
15
- ```全体のコード
16
- import { registerRootComponent } from 'expo';
17
- import React, { useState } from 'react';
18
- import { View, Text, TextInput, TouchableOpacity, StyleSheet } from 'react-native';
19
- import { Icon } from 'react-native-elements';
20
- import { SwipeListView } from 'react-native-swipe-list-view';
21
-
22
- const App = () => {
23
- const [task, setTask] = useState('');
24
- const [tasks, setTasks] = useState([]);
25
- const [isPressed, setIsPressed] = useState(false);
26
-
27
- const addTask = () => {
28
- if (task.trim() !== '') {
29
- setTasks([...tasks, task]);
30
- setTask('');
31
- }
32
- };
33
-
34
- const removeTask = (index) => {
35
- const newTasks = [...tasks];
36
- newTasks.splice(index, 1);
37
- setTasks(newTasks);
38
- };
39
-
40
- const handlePress = () => {
41
- setIsPressed(!isPressed);
42
- };
43
-
44
- return (
45
- <View style={styles.container}>
46
- <View style={styles.inputContainer}>
47
- <TextInput
48
- style={styles.input}
49
- placeholder="タスクの追加"
50
- value={task}
51
- returnKeyType="done"
52
- onSubmitEditing={addTask}
53
- onChangeText={(text) => setTask(text)}
54
- />
55
- </View>
56
- <SwipeListView
57
- data={tasks}
58
- keyExtractor={(index) => index.toString()}
59
- renderItem={({ item }) => (
60
- <View style={styles.taskItem}>
61
- <Text style={isPressed ? styles.doneTaskItem : null}>{item}</Text>
62
- </View>
63
- )}
64
- renderHiddenItem={({ index }) => (
65
- <View style={styles.hiddenItemContainer}>
66
- <TouchableOpacity style={[styles.taskButton, styles.doneButton]} onPress={handlePress}>
67
- <Icon name="done" size={20} color="white" />
68
- </TouchableOpacity>
69
- <TouchableOpacity
70
- style={[styles.taskButton, styles.deleteButton]}
71
- onPress={() => removeTask(index)}
72
- >
73
- <Icon name="delete" size={20} color="white" />
74
- </TouchableOpacity>
75
- </View>
76
- )}
77
- rightOpenValue={-100}
78
- />
79
- </View>
80
- );
81
- };
82
-
83
- const styles = StyleSheet.create({
84
- container: {
85
- flex: 1,
86
- padding: 20,
87
- backgroundColor: 'white',
88
- },
89
- inputContainer: {
90
- flexDirection: 'row',
91
- marginTop: 100,
92
- marginBottom: 10,
93
- },
94
- input: {
95
- flex: 1,
96
- height: 40,
97
- borderWidth: 1,
98
- borderColor: 'gray',
99
- marginRight: 10,
100
- paddingHorizontal: 10,
101
- },
102
- taskItem: {
103
- backgroundColor: 'white',
104
- justifyContent: 'center',
105
- height: 50,
106
- },
107
- doneTaskItem: {
108
- color: 'gray',
109
- textDecorationLine: 'line-through',
110
- },
111
- hiddenItemContainer: {
112
- flexDirection: 'row',
113
- justifyContent: 'flex-end',
114
- alignItems: 'center',
115
- height: '100%',
116
- },
117
- taskButton: {
118
- padding: 10,
119
- },
120
- doneButton: {
121
- backgroundColor: 'gray',
122
- },
123
- deleteButton: {
124
- backgroundColor: 'red',
125
- },
126
- });
127
-
128
- export default registerRootComponent(App);
129
-
130
- ```
131
12
 
132
13
  ```DOMの当該のコード
133
14
  <SwipeListView