当从浏览器单击链接时,如何打开 React Native 应用程序的特定屏幕?

问题描述

我使用 Expo 创建了一个 React Native 应用程序。当用户点击如下链接时,如何打开应用的特定屏幕:

public class posScreen extends AppCompatActivity {
ViewPager viewPager;
ViewPagerAdapter viewPagerAdapter;
private TextView tabMeals,tabSides,tabCheckout;

public posScreen() {
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_pos_screen);
    this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);

    //Tab Resources
    tabMeals = findViewById(R.id.meals_tab);
    tabSides = findViewById(R.id.sides_tab);
    tabCheckout = findViewById(R.id.checkout_tab);
    viewPager = findViewById(R.id.FragContainer);

    tabMeals.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(0);
        }
    });
    tabSides.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(1);
        }
    });
    tabCheckout.setonClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            viewPager.setCurrentItem(2);
        }
    });

    viewPagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
    viewPager.setAdapter(viewPagerAdapter);

    viewPager.addOnPagechangelistener(new ViewPager.SimpleOnPagechangelistener() {
        @Override
        public void onPageScrolled(int position,float positionOffset,int positionOffsetPixels) {

        }

        @Override
        public void onPageSelected(int position) {
            onChangeTab(position);
        }

        @Override
        public void onPageScrollStateChanged(int state) {

        }
    });

}

private void onChangeTab(int position) {
    if(position == 0) {
        tabMeals.setTextSize(30);
        tabSides.setTextSize(20);
        tabCheckout.setTextSize(20);
    } else if(position == 1) {
        tabMeals.setTextSize(20);
        tabSides.setTextSize(30);
        tabCheckout.setTextSize(20);
    } else if(position == 2) {
        tabMeals.setTextSize(20);
        tabSides.setTextSize(20);
        tabCheckout.setTextSize(30);
    }
}

根据我的研究,我安装了 <?xml version="1.0" encoding="utf-8"?> <androidx.appcompat.widget.LinearLayoutCompat xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="wrap_content" tools:context=".posScreen"> <androidx.viewpager.widget.ViewPager android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/FragContainer" android:layout_marginTop="50dp"/> <com.google.android.material.tabs.TabLayout android:id="@+id/tabLayout" android:layout_width="0dp" android:layout_height="wrap_content" app:layout_constraintEnd_toEndOf="parent" app:layout_constraintStart_toStartOf="parent" app:layout_constraintTop_toTopOf="parent"> <com.google.android.material.tabs.TabItem android:id="@+id/meals_tab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Meals" /> <com.google.android.material.tabs.TabItem android:id="@+id/sides_tab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Sides and Drinks" /> <com.google.android.material.tabs.TabItem android:id="@+id/checkout_tab" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Checkout" /> </com.google.android.material.tabs.TabLayout> </androidx.appcompat.widget.LinearLayoutCompat> ,并在 https://staging.wapal.com/reset/password?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJlbWFpbCI6ImJhc2lycnBheWVuZGFAZ21hSI6InBhc3N3b3JkUmVzZXQiLC12J1c2VyX2lkIjoxOTYsImlhdCI6MTYyNzQ4ODM1OSwiZXhwIjoxNjI3ND3123kxOTU5fQ.LZZvXNnlsLMEB4YWwojRvbiz8PPwRMq1QQPyJZrakls 中进行了如下配置:

expo-linking

可能有些部分我没有从文档中理解并且没有得到预期的结果。我该如何解决这个问题?

提前致谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)