Giter VIP home page Giter VIP logo

muramrr / material-backdrop-android Goto Github PK

View Code? Open in Web Editor NEW
5.0 1.0 0.0 2.07 MB

Android material backdrop representation using only native solution, without third-party libraries or other overengineered variants like coordinator + BottomSheet etc.

Kotlin 100.00%
motionlayout backdrop material-ui material-design android-material android-motionlayout android-backdrop backdrop-material android-ui android-kotlin motion-layout material-backdrop

material-backdrop-android's Introduction

Backdrop-MotionLayout

Android material backdrop

sample

Material backdrop concept representation in Android as simple as possible.

See Material guidelines for backdrop

Explanations

Only base features of MotionLayout used to achieve such behaviour.

<MotionScene ...
  >
	
  <Transition app:constraintSetStart="@id/backdropCollapsed"
    app:constraintSetEnd="@id/backdropExpanded">
		
    <OnSwipe app:dragDirection="dragUp"
      app:touchAnchorId="@id/frontContentContainer"
      app:dragScale="1.5" <-- makes swipe more natural by increasing its scale by 150%
      app:nestedScrollFlags="disableScroll" <-- important, this flag prevent -->
      <-- starting transition when RecyclerView reaches the start (or the end) after scroll -->
      />
		
    ...
	
  </Transition>
  
  
  <ConstraintSet android:id="@+id/backdropCollapsed" /> <-- base state (mathes our activity_main.xml) -->
	
  <ConstraintSet android:id="@+id/backdropExpanded">

    <Constraint android:id="@+id/frontContentContainer"
      android:layout_width="0dp"
      android:layout_height="0dp"

      app:layout_constraintBottom_toBottomOf="parent"
      app:layout_constraintStart_toStartOf="parent"
      app:layout_constraintEnd_toEndOf="parent"
      
      app:layout_constraintTop_toBottomOf="@id/backdropBackground"  <-- main difference,
      <--  makes our RecyclerView container align bottom of backdrop content -->
      <--  this gives us imitation of BottomSheet appearance and elevation -->
     
      />

  </ConstraintSet>


</MotionScene>

How it can be done another simple way?

You can opt out of using the MotionLayout, make all the same in ConstraintLayout or FrameLayout as a main container.

Place all staff one on top of the other and use something like this:

//register container swipe listener
...a lot of code here...

//somewhere in your listener
//calculate your backdrop content bottom coords
val backdropBottom = containerBackdrop.height // the real case could be more complex
...
//this will slide your front content to bottom
FrontContentContainer.animate().translationY(backdropBottom).start()
...

//this will slide your front content back
FrontContentContainer.animate().translationY(initPos).start()

material-backdrop-android's People

Contributors

muramrr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.