I want to make RiveAnimationView animate and open navigation drawer in Android with kotlin But when I click on it it's animated but IT didn't open the navDrawer because setOnClickListener didn't Work it have his own click animation listener in rive so how to make this listener interact with my view open drawer or do any other thing when click on the RiveAnimationView
class NavDrawer2 : AppCompatActivity() {
private lateinit var binding: ActivityNavDrawer2Binding
internal var drawerListener: DrawerLayout.DrawerListener? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityNavDrawer2Binding.inflate(layoutInflater)
setContentView(binding.root)
setSupportActionBar(binding.appBarNavDrawer2.toolbar)
val drawerLayout: DrawerLayout = binding.drawerLayout
binding.navMenu2.setOnClickListener {
drawerLayout.openDrawer(GravityCompat.START)
}
drawerListener=object : DrawerLayout.DrawerListener{
override fun onDrawerSlide(drawerView: View, slideOffset: Float) {
}
override fun onDrawerOpened(drawerView: View) {
binding.navMenu2.setBooleanState("State Machine 1","isOpen",false)
}
override fun onDrawerClosed(drawerView: View) {
binding.navMenu2.setBooleanState("State Machine 1","isOpen",true)
}
override fun onDrawerStateChanged(newState: Int) {
}
}
drawerLayout.addDrawerListener(drawerListener!!)
}
}
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
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_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<androidx.drawerlayout.widget.DrawerLayout
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:openDrawer="start">
<include
android:id="@+id/app_bar_nav_drawer2"
layout="@layout/app_bar_nav_drawer2"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<com.google.android.material.navigation.NavigationView
android:id="@+id/nav_view"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="start"
android:fitsSystemWindows="true"
app:headerLayout="@layout/nav_header_nav_drawer2"
app:menu="@menu/activity_main_drawer" />
</androidx.drawerlayout.widget.DrawerLayout>
<app.rive.runtime.kotlin.RiveAnimationView
android:id="@+id/navMenu2"
android:layout_width="50dp"
android:layout_height="50dp"
app:riveResource="@raw/menu_button"
app:riveAutoPlay="false"
android:clickable="true"
android:focusable="true"
app:riveTouchPassThrough="false"
app:riveRenderer="Rive"
/>
</FrameLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout 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="match_parent"
tools:context=".NavDrawer2">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/Theme.Night_switcher.AppBarOverlay">
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/Theme.Night_switcher.PopupOverlay" />
</com.google.android.material.appbar.AppBarLayout>
<include layout="@layout/content_nav_drawer2" />
</androidx.coordinatorlayout.widget.CoordinatorLayout>
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_nav_drawer2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Main Content"
android:textSize="40sp"
android:gravity="center"/>
</androidx.constraintlayout.widget.ConstraintLayout>
nav_header_nav_drawer2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="@dimen/nav_header_height"
android:background="@drawable/side_nav_bar"
android:gravity="bottom"
android:orientation="vertical"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark">
<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/nav_header_desc"
android:paddingTop="@dimen/nav_header_vertical_spacing"
app:srcCompat="@mipmap/ic_launcher_round" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="@dimen/nav_header_vertical_spacing"
android:text="@string/nav_header_title"
android:textAppearance="@style/TextAppearance.AppCompat.Body1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/nav_header_subtitle" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
tools:showIn="navigation_view">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_home"
android:icon="@drawable/ic_menu_camera"
android:title="@string/menu_home" />
<item
android:id="@+id/nav_gallery"
android:icon="@drawable/ic_menu_gallery"
android:title="@string/menu_gallery" />
<item
android:id="@+id/nav_slideshow"
android:icon="@drawable/ic_menu_slideshow"
android:title="@string/menu_slideshow" />
</group>
</menu>
I tried used in in a frameLayout and setBooleanState when click on this frame and its working good but i wonder know if i can Trigger click on the RiveAnimationView directly without wrapping it inside a frame or using setOnClickListener to it to make it open the navDrawer or do anything else ...
The only solution i get for now is to wrap the RiveAnimationView inside a framelayout and make this frame clickable and focusable. Then make clicklistener open the navDrawer and close It if it was opened... I make another .riv file that is set to control animation with number input from 0 to 1 an that makes the animation cool with sliding ( 0f- to 1f) so i Set this animation only on OnSlide méthode of the navDrawer so it Auto Slide when click button or when manually slide It and the animation now works really good..