Tautan artikel
React Native Community belum menerbitkan dokumen atau sumber resmi apa pun untuk mewujudkan gerakan sentuh drag-drop-swipe pada komponen. Saya telah beberapa pengalaman tentang penggunaan gerakan sentuh pada komponen beberapa proyek jadi, saya sudah mencoba menunjukkan fitur ini pada aplikasi asli React Native. Saya harap ini akan membantu Anda.
Mari kita mulai menginstal paket yang diperlukan.
yarn installAda beberapa baris yang perlu kita tambahkan di sisi Android .. Langkah ini tidak diperlukan untuk iOS .. Garis yang akan ditambahkan ditunjukkan dengan "+". Jalurnya adalah, android/app/src/main/java/mainactivity.java
package com . gesturehandler ;
import com . facebook . react . ReactActivity ;
+ import com . facebook . react . ReactActivityDelegate ;
+ import com . facebook . react . ReactRootView ;
+ import com . swmansion . gesturehandler . react . RNGestureHandlerEnabledRootView ;
public class MainActivity extends ReactActivity {
/**
* Returns the name of the main component registered from JavaScript. This is used to schedule
* rendering of the component.
*/
@ Override
protected String getMainComponentName ( ) {
return "gestureHandler" ;
}
+ @ Override
+ protected ReactActivityDelegate createReactActivityDelegate ( ) {
+ return new ReactActivityDelegate ( this , getMainComponentName ( ) ) {
+ @ Override
+ protected ReactRootView createRootView ( ) {
+ return new RNGestureHandlerEnabledRootView ( MainActivity . this ) ;
+ }
+ } ;
+ }
}Contoh aplikasi kami siap!
yarn run androidKami dapat menjalankannya dengan perintah tertulis di atas pada emulator Android.